Assets: better cache management. #8006
henzeb
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am just in to statamic, and I really love it. It's simple to set up, everything can be adapted, and there are eloquent drivers too!
One thing however was bugging me and that is the cache management of Assets. Consider the following disk setup:
Obviously, the image-storage is the one you use inside your Assets Container. It's where the originals are stored.
and in your assets.php config you point to the other:
Works like a charm. when you upload an image, any presets you configured is being generated.
Now, suppose you want to change the focal point. you can edit all you want, the focal point gets stored, but the image on your frontend never changes. They have added something called "replace image" or "re-upload", but that clutters up your cache and is definitely not user friendly. You could also go into your console and run that statamic:glide:clear command. But if your users aren't that technical, they will ask you.
Luckily, they emit events.
That's it. The event listener is queued and will check if the asset that was saved was an image and if so, tells Glide to clear it's cache and regenerate the assets. It's a simple example, but you could do some more checks.
Statamic also won't delete the cache when deleting an image. If that concerns you, you can listen to AssetDeleted:
This solution was brought to you by ChatGPT-4 and is modified to actually working code by me.
Beta Was this translation helpful? Give feedback.
All reactions