Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear cache does not clear /storage/views #2630

Closed
ctml91 opened this issue Feb 23, 2021 · 4 comments
Closed

clear cache does not clear /storage/views #2630

ctml91 opened this issue Feb 23, 2021 · 4 comments

Comments

@ctml91
Copy link
Contributor

ctml91 commented Feb 23, 2021

Bug Report / Feature Request

Current Behavior
php flarum cache:clear does not clear old blade templates under storage/views

Steps to Reproduce

  1. Over time the files under storage/views seem to build up
  2. They can cause issues as shown in this discuss thread

Expected Behavior
These files should be cached and cleared when executing php flarum cache:clear

@emamulkhan
Copy link
Contributor

I am taking up this issue, i discussed it with @askvortsov1 in #internal chat. Below are the solutions we discussed for now.

There's 2 things that need to be done:
in https://github.com/flarum/core/blob/ea291508ab954a04682927ebe3bfafbfb584e752/src/Foundation/Console/CacheClearCommand.php#L17-L17, a line needs to be added that removes the contents of the storage/views directory (like is currently done with formatter and locale (maybe less could be added there too)

in https://github.com/flarum/core/blob/ea291508ab954a04682927ebe3bfafbfb584e752/src/Extend/View.php#L16-L16, when extensions that add/remove views are enabled/disabled, the view cache should probably be cleared too

@askvortsov1
Copy link
Sponsor Member

, when extensions that add/remove views are enabled/disabled, the view cache should probably be cleared too

To clarify this one, it needs to implement LifecycleInterface, which will automatically run the relevant methods on enable/disable. The Formatting extender is a good example of this.

@emamulkhan
Copy link
Contributor

@askvortsov1 - By using LifecycleInterface i can use onEnable and onDisable, However if i want to use Repository (Illuminate\Contracts\Cache\Repository) forget method inside Extend/View.php, could you please guide me how can i do that in https://github.com/flarum/core/blob/ea291508ab954a04682927ebe3bfafbfb584e752/src/Extend/View.php#L16-L16

@askvortsov1
Copy link
Sponsor Member

Although using repository would be a nice abstraction, we don't currently do so for views; that's hardcoded to use the same filesystem that Flarum is installed on (revamping that would be nice, that's part of the stuff I mentioned above for potential long term improveents, but probably quite complicated). So for now, I'd say that part of cache should be cleared in the same way that it'll need to be implemented in ClearCacheCommand, that is, something along the lines of

array_map('unlink', glob($storagePath.'/views/*'));

The storage path can be gotten via $container->make(Paths::class)->storage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants