strapi-plugin-local-image-sharp icon indicating copy to clipboard operation
strapi-plugin-local-image-sharp copied to clipboard

Cache images?

Open ohbob opened this issue 2 years ago • 13 comments

Is there a way once requested the image is being cached forever? I don't want to regenerate the image on each call.

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
        <img alt="image" src="http://localhost:1337/uploads/f_avif,q_70,w_920/F_Sp8o_KVIAA_0_U7b_bc59f01efd.jpg">
</body>
</html>

ohbob avatar Jun 03 '22 20:06 ohbob

Yes. Set a cache rule on your server.

Sandstedt avatar Jun 03 '22 22:06 Sandstedt

Yes. Set a cache rule on your server.

Could you give an example please?

ohbob avatar Jun 04 '22 04:06 ohbob

Ngnix: https://linuxhint.com/cache-static-resources-https-nginx/

Apache: https://www.faqforge.com/linux/enable-image-caching-in-apache-for-better-google-page-speed-results/

Sandstedt avatar Jun 06 '22 04:06 Sandstedt

If your using something like next.js and next/image, there is some cache settings to be set there: In next.config.js you can set the images cache duration. If you have no cache on the server, and haven't set minimumCacheTTL, then you images will get thrown away as soon as they have been generated.

https://nextjs.org/docs/api-reference/next/image#caching-behavior

Sandstedt avatar Jun 06 '22 05:06 Sandstedt

do i understand this right, the caching is happening on the client side for the front end? If that's the case, seems a bit odd, that it's not being cached at backend..

ohbob avatar Jun 06 '22 15:06 ohbob

Oh sorry, mixed together this issue with a next/image thread I'm getting a lot of updates on. Edited.

Sandstedt avatar Jun 09 '22 20:06 Sandstedt

But I would recommending using a cache layer in front of this plugin. Wouldn't not expect that's in the scope of this plugin, it has just a single purpose, to generate an images based on the parameters I send to it. See it like a microservice. Cause caching all depends on the rest of the setup in your project. If your using something like Gatsby or Next.js, it will be build into the framework.

Sandstedt avatar Jun 09 '22 20:06 Sandstedt

it has just a single purpose, to generate an images based on the parameters I send to it

The generated image is not saved in the filesystem, am I right?

Thanks

c3s4 avatar Jun 13 '22 08:06 c3s4

You can now set maxAge properly in the plugin setting. Before v1.2.0 this setting were not used by ipx, it was fixed on https://github.com/unjs/ipx/pull/71 so browser cache should now work as expected!

About server side caching, for now images are not stored anywhere. We can extend https://github.com/strapi-community/strapi-plugin-rest-cache to allow caching assets?

stafyniaksacha avatar Jul 28 '22 16:07 stafyniaksacha

please extend serverside caching of images

ohbob avatar Sep 16 '22 20:09 ohbob

+1 is this something planned in the future?

kevin-chassagne avatar Sep 23 '22 11:09 kevin-chassagne

You can now set maxAge properly in the plugin setting. Before v1.2.0 this setting were not used by ipx, it was fixed on https://github.com/unjs/ipx/pull/71 so browser cache should now work as expected!

About server side caching, for now images are not stored anywhere. We can extend https://github.com/strapi-community/strapi-plugin-rest-cache to allow caching assets?

Any progress on this? I really want this to become a reality) how can I help?

ohbob avatar Oct 22 '22 19:10 ohbob

I do not have too much time to work on this at now, sorry! If someone could open a PR I will take time to review/publish, that would be appreciated.

stafyniaksacha avatar Oct 24 '22 11:10 stafyniaksacha

Hello there!

The feature is done in v1.4.0: https://strapi-community.github.io/strapi-plugin-local-image-sharp/guide/#configuration

Also, the new documentation is online! Feedback is welcome!

stafyniaksacha avatar Jan 06 '23 03:01 stafyniaksacha

How do you manage when you change the image? because the reiszed images are cached and not change. How can i flush that specific image cache?

martin-landhi avatar Jun 14 '23 14:06 martin-landhi