Skip to content
Browse files

using the cacheManager->delete method

  • Loading branch information...
1 parent 3859a65 commit 222588873a8d09a45a337b61e16b555035549572 @myfreeweb committed
Showing with 6 additions and 14 deletions.
  1. +1 −3 README.md
  2. +5 −11 core/components/uncacher/model/uncacher/uncacher.class.php
View
4 README.md
@@ -10,8 +10,6 @@ First, download and install it with the MODX package manager (System, Package Ma
Second, uncheck the "Empty Cache" flag on every resource you edit.
-And make sure you're using `xPDOFileCache` as `cache_handler` – the Memcache handler doesn't support clearing the cache of just one resource.
-
If you don't use the publishing-at-a-specified-time functionality, you can stop reading right there.
If you do need it, set [CronManager](http://rtfm.modx.com/display/ADDON/CronManager) up and add a cron job calling the `uncacheRecent` snippet every `n` minutes and with options `minutes: n`, where `n` is how often to check. Five minutes is a good choice, but you can set it to one minute if you need that much precision.
@@ -20,4 +18,4 @@ If you do need it, set [CronManager](http://rtfm.modx.com/display/ADDON/CronMana
## Hacking
Uncacher is tested with [Behat](http://behat.org) and built like any other MODX package (`php _build/build.transport.php`).
-By default, it assumes you have MODX installed in ~/Sites; if you don't, set the `MODX_PATH` environment variable to the path to your MODX installation.
+By default, it assumes you have MODX installed in ~/Sites; if you don't, set the `MODX_PATH` environment variable to the path to your MODX installation.
View
16 core/components/uncacher/model/uncacher/uncacher.class.php
@@ -52,17 +52,11 @@ function uncache(&$res, $recache) {
// Re-cache resources
foreach ($resources as $res) {
- $path = MODX_CORE_PATH.'cache/resource/'.$res->get('context_key').'/resources/'.$res->get('id');
- $fpath = $path.'.cache.php'; // TODO: support json and serialized cache? who ever uses it?
-
- if (is_dir($path)) {
- $this->modx->log(modX::LOG_LEVEL_INFO, 'Uncacher deleting '.$path);
- $this->modx->cacheManager->deleteTree($path, array('deleteTop' => true));
- }
- if (is_file($fpath)) {
- $this->modx->log(modX::LOG_LEVEL_INFO, 'Uncacher deleting '.$fpath);
- unlink($fpath);
- }
+ $this->modx->cacheManager->delete($res->getCacheKey(), array(
+ xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_resource_key', null, 'resource'),
+ xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_resource_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)),
+ xPDO::OPT_CACHE_FORMAT => (integer) $this->modx->getOption('cache_resource_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)))
+ );
if ($recache == true) {
file_get_contents($this->modx->makeUrl($res->get('id'), '', '', 'full'));
}

0 comments on commit 2225888

Please sign in to comment.
Something went wrong with that request. Please try again.