All for creating and promoting websites

Layout, programming, web tools

Clearing the cache resource in MODX Revo

Clearing the cache resource in MODX Revo

In developing their snippets for MODX, sometimes there is a problem with caching. You have made some changes, and the data are given old and even the "!" when calling does not help.

So I present a small script that cleans the cache of the current resource. You can paste it in the snippet or to create a new, clean to clean.

$id = $modx->resource->get('id');
$docObj = $modx->getObject('modResource',$id);// $docObj - a resource object whose cache should be cleaned
$key = $docObj->getCacheKey(); 
$cache = $modx->cacheManager->getCacheProvider($modx->getOption('cache_resource_key', null, 'resource'));
$cache->delete($key, array('deleteTop' => true));
$cache->delete($key);

I recommend to insert it in front of their snippets (or in the top lines of your snippet).

Highlight found mistake and press Ctrl + Enter to notify the administrator.