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

Cache images? #3

Closed
ohbob opened this issue Jun 3, 2022 · 15 comments
Closed

Cache images? #3

ohbob opened this issue Jun 3, 2022 · 15 comments

Comments

@ohbob
Copy link

ohbob commented Jun 3, 2022

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>
@Sandstedt
Copy link

Sandstedt commented Jun 3, 2022

Yes. Set a cache rule on your server.

@ohbob
Copy link
Author

ohbob commented Jun 4, 2022

Yes. Set a cache rule on your server.

Could you give an example please?

@Sandstedt
Copy link

Sandstedt commented Jun 6, 2022

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

@ohbob
Copy link
Author

ohbob commented Jun 6, 2022

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..

@Sandstedt
Copy link

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

@Sandstedt
Copy link

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.

@c3s4
Copy link

c3s4 commented Jun 13, 2022

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

@stafyniaksacha
Copy link
Member

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 unjs/ipx#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?

@ohbob
Copy link
Author

ohbob commented Sep 16, 2022

please extend serverside caching of images

@kevin-chassagne
Copy link

+1 is this something planned in the future?

@ohbob
Copy link
Author

ohbob commented Oct 22, 2022

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 unjs/ipx#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?

@stafyniaksacha
Copy link
Member

stafyniaksacha commented Oct 24, 2022

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
Copy link
Member

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!

@martin-landhi
Copy link

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?

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

No branches or pull requests

6 participants