Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

How to Enable the Default WordPress Object Cache

Recently, while attempting to optimize site performance, I found myself experimenting with various caching mechanisms currently available for WordPress. Specifically, I explored each of the following caching options:

  • WP-Cache 2 [WordPress plugin]
  • WP Super Cache [WordPress plugin]
  • WordPress Object Cache [built-in caching mechanism]

While working with the two plugins, WP Cache 2 and Super Cache, I was pleased to discover crystal-clear instructions on each their respective sites. Having access to installation and usage information greatly facilitated the implementation of each of these caching techniques.

On the other hand, finding information about the default WordPress object cache proved virtually impossible. Finally, after locating some decent information, I was able to confirm my initial suspicions and subsequently decided to post a quick article outlining and describing this very straightforward caching method. Although enabling the WordPress cache turns out to be drop-dead easy, it is always good to be sure that you aren’t forgetting a step or otherwise overlooking some important aspect of the process.

Enable default WordPress cache in 3 easy steps

Note: This information applies to WordPress versions less than 2.5 only.

Ready? Implementing the default WordPress object cache is remarkably simple..

Step 1: Enable the caching mechanism

Open wp-config.php and set the value of ENABLE_CACHE to “TRUE”:

define('ENABLE_CACHE', TRUE);

Step 2: Create the cache directory

Create a folder called “cache” and place it within the wp-content directory:

/wp-content/cache/

Step 3: Make the cache folder writable

Ensure that the folder is writable by setting its permissions to 755 or 777.

Done!

Testing

Once you have everything setup, surf around your site and check things out by reloading a few different pages. If the WordPress default object cache is working correctly, you will see a newly added slew of temporary cache files along with a newly created index.php file and wp_object_cache.lock file within the cache directory. Thus, if you don’t see any such files in the cache directory after surfing around your site, go back and recheck that you have correctly executed the proper steps. Note: if nothing seems to be happening with your cache — i.e., no cache files are being generated — you may want to try “rebooting the cache” via the following procedure:

  1. Disable the cache in wp-config.php
  2. Delete the cache directory completely from your server1
  3. Create a new cache directory, set the permissions, and re-enable caching in wp-config.php

I have also had luck simply deleting the cache directory and letting WordPress recreate it automatically. Remember, if it doesn’t work the first few times, try a few more times before giving up — it does work!

Winning

After you have confirmed that the object cache is working, you’re done. From that point on, or until you disable it, the cache should work as intended, saving you bandwidth resources and saving your visitors time. To verify this, navigate to a long-lost post that is buried way back in your archives somewhere — something that is completely off the radar. As you visit, note the page loading time. Now, visit the page again and compare the results. On average, while the native object cache is nowhere near as effective as either plugin method, it does manage to shave off a noticeable amount of loading time for your visitors.

Wrapping

Although the WordPress object cache may not work as well as either of the cache plugins currently available, it is an effective caching method that is a breeze to setup and run. And, best of all, the default caching mechanism works perfectly with virtually all WordPress plugins.

Footnotes

  • 1 Note: One final note concerning the WordPress object cache: all of the files may be safely deleted at your discretion — everything is regenerated automagically ;)

About the Author
Jeff Starr = Web Developer. Security Specialist. WordPress Buff.
SAC Pro: Unlimited chats.

32 responses to “How to Enable the Default WordPress Object Cache”

  1. There is something wrong wordpress2.7

  2. Jeff Starr 2008/12/09 8:25 am

    @btFish: Check out comment number eleven for an explanation.

  3. Thanks for this bit of illumination on a dark topic. It still seems a bit mysterious to me what the object cache does since the removal of file-based caching. Are cached objects no longer persistent across requests? And why are there still freshly dated files the cache directory of my WP 2.7 installation?

    Look at the code I would guess the answer to the first question is no, but the second question makes me think I’m missing something.

    As a plugin author, I’d like to be able to cache things persistantly without depending on other plugins, but it’s not clear that the object cache provides this ability.

  4. WordPress bigger 2.6 has not a cache-directory, WP has now a object-cache.

  5. Jeff, I too tried several attempts but no success yet on this one.

    Do I need to have Wp-Cache2 and Wp-Super-Cache plugins installed to enable this built-in feature?

    Thanks, JK

  6. @cyberhobo, @JK: As mentioned in comment #11, the file-based object cache has been removed from all WordPress versions 2.5 or better.

  7. Thanks for answering. The files in the cache directory that are puzzling me must be created by something else. They are named with a hash ending in .spc.

  8. Maybe you should add a warning at the top of this article, that one can no longer (do the title of this article) “Enable the Default WordPress Object Cache”, (which is apparently the case, if one reads through the comments.) And mention if there is any built in alternatives, or must one resort to plugins? Thanks.

  9. Jeff Starr 2009/02/15 9:11 am

    @jidanni: Thanks for the advice. I have included a note to this effect in the article. Cheers!

  10. php trivandrum 2009/05/11 5:10 pm

    On an academic interest resurrected the file based object cache for wordpress. http://www.php-trivandrum.org/wordpress-plugins/wordpress-object-caching-in-file-system.html

  11. Jeff Starr 2009/05/12 3:44 pm

    @php trivandrum: Good stuff! Thanks for sharing! :)

  12. I’m working on a PHP Object Cache. An implementation for wordpress is coming along:

    http://code.google.com/p/php-object-cache/

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
SAC Pro: Unlimited chats.
Thoughts
I disabled AI in Google search results. It was making me lazy.
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources. Also: “The Web” is not a valid answer.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.