Standard location for plugin to save/cache files?

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.

3 s
3

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.

Leave a Comment