Where should a plugin or widget cache its results?

Where should a plugin cache its re-usable results?

I have read the code of several well-used WordPress plugins, and it seems that the answer is not consistent. I have written several plugins myself, and I store things in a cache directory. But I just picked the location of the directory out of a hat, and my code creates the cache directory if it doesn’t exist. This seems arbitrary.

Read More

I know there are plugins that do caching. Suppose I don’t want to use a plugin. I find that relying on the filesystem to cache results is easy for maintenance, diagnostics, and performance.

Is there a good, more-or-less standard approach, or a blessed approach, to choosing a filesystem location for a cache?

Related posts

Leave a Reply

1 comment

  1. I find that relying on the filesystem to cache results is easy for maintenance, diagnostics, and performance.

    Please note that this might be true in some (maybe even most) circumstances, but not all of them. If your code is meant for anything beyond personal usage you don’t know with which file system and hardware will it be used and how will it perform there.

    WP is engineered to use database for storage of textual data, that is more typical and logical first choice than file system.

    Is there a good, more-or-less standard approach, or a blessed approach, to choosing a filesystem location for a cache?

    wp-content folder is meant as a place for files uploaded or generated during operation. Plugins that use file cache should create folder for it in there. Note that WP is flexible about most of folder structure and it can be easily renamed/relocated from defaults – use appropriate functions to determine that rather than hardcode default path.