OllieJones / sqlite-object-cache

A WordPress persistent object cache for the rest of us.
GNU General Public License v2.0
24 stars 4 forks source link

Cache expiry #28

Closed spacedmonkey closed 1 year ago

spacedmonkey commented 1 year ago

When setting a key in cache you can set the expiration time. How is this happened in this plugin?

OllieJones commented 1 year ago

From an hourly WP_Cron job, this line of code wipes expired cache entries.

https://github.com/OllieJones/sqlite-object-cache/blob/trunk/assets/drop-in/object-cache.php#L903

When looking up cache entries, this line of code suppresses retrieving expired ones.

https://github.com/OllieJones/sqlite-object-cache/blob/trunk/assets/drop-in/object-cache.php#L647

This is a pretty common pattern in SQL-based code; use WHERE filters to suppress expired data, then clean it up in batches.

You can take a look at the contents of the cache database yourself while it is in use with an sqlite3 command line client. Just be sure to run that client with the same user privs as your web server, or you'll create temp files that the web server can't access.

sudo -u www-data sqlite3 wp-content/.ht.object-cache.sqlite

(Put in your own .sqlite file, obviously. This is the default one.)