1

I'm working on a new plugin, and i need to write a frew cache files somewhere.

At first i wanted to create a cache folder inside my plugin with the following .gitignore file in it:

# Ignore everything in this directory
*
# Except this file
!.gitignore

But when i checkout the plugin in a new project, this folder is not writeable. Obivously I do not want the user to go to the commandline and set this folder's permission with chmod (not everyone is able to do this).

Does anyone know an alternative location where I can save my cache files?

Thanks in advance!

2
  • why not use the wp-content folder or the wp-uploads folder for the site? I'm assuming the cache would be loaded specific to the site since it is a plugin and wouldn't be shipped with the plugin (since you've specified that it's ignored. Apr 10, 2014 at 11:34
  • Jup, it's specific to the site. I guess i can use the wp upload folder, but that might be adding some files to their versioning for some people.
    – Paul
    Apr 10, 2014 at 15:36

1 Answer 1

3

If you observe how the popular caching plugins like WP Super Cache or W3TC utilize a cache folder within wp-content as well as other plugins who utilize uploads or cachable files it would be appropriate to create a folder within that structure. A side issue may arise if the user has a locked down folder structure as you indicated and the plugins folder may be one of those protected areas. In my experience I have seen site owners lock down the file system with flags for cache and uploads in the wp-content folder and this would present a compatiblity challenge for your plugin. Thus in order to be as "WordPressy" as possible I would recommend as a practice to adhere to the general practice of storing created files in appropriate areas that are commonly associated with dynamicly created static assets.

The larger issue of storing static files within your plugin folder is when a plugin update occurs the cached files will be wiped because the folder is replaced during the update process. Again without a custom update mechanism within your plugin (which would prevent it from being submitted to .org repo) you are left with a performance hit on the cached files everytime an update occurs to the code vs the content/usage.

In response to the clarification comments, in theory/practice versioning systems shouldn't track the uploads unless the sql is also versioned which in this case I wouldn't be too concerned about it.

1
  • 1
    Content uploads folder (not just content) is pretty much only place in WP as close to be available for painless file storage as it gets (otherwise core itself cannot properly write things there).
    – Rarst
    Apr 10, 2014 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.