Question

Are there official guidelines on where a plugin should cache files?

If not, is there a best-practice out there that I can follow?

For example, a plugin grabs content from a back-end system benefits from caching the file so it doesn't repeatedly fetch the same content from the back-end.

Searching here and elsewhere is tough as most queries lead to caching plugins or database tutorials.

My instinct says to put them into a sub-directory of wp-content/uploads.

My secondary instinct would be to keep the files within the plugin's directory tree. This keeps plugin data grouped together but doesn't follow (what appears to be) WordPress architecture where user content is in /uploads.

Was it helpful?

Solution

It would be nice if WordPress had a standards based cache directory, but since it doesn't I think the best option is to keep it in the plugin folder itself.

Uploads are in my opinion for actual uploads and cache files are not really considered as such. I think it easier to manage , reduces possible conflicts and to be honest it's where I would look if a plugin has this functionality.

tl;dr: The cache files are part of the functionality of a specific plugin and should be packaged with it.

OTHER TIPS

If you don't need to store very large data you should take a look to the Wordpress Transient API:

http://codex.wordpress.org/Transients_API

Your data will be handled by Wordpress with an expiration time. I think it is the more "wordpress-way" to cache data.

Sitting with the same "problem". At first i was thinking of store this cache as an option, but my cache simply was too big so this did not work. So maybe that's an alternative if your cache never will be really large. For example if you're communicating with an API and can only do a few requests per hour and that the return answer is not too long. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top