The MODX cache is partitioned so that specific sections can be cleared in total. Not all cache implementations provide a way to remove specific keys within the cache efficiently, so in general, if you want to clear things manually, and not when the context cache or the resource cache is cleared (for instance), you should use a custom partition by specifying an existing cache partition (identified by xPDO::OPT_CACHE_KEY):
<?php
$cacheOptions = array(
xPDO::OPT_CACHE_KEY => 'myCache',
xPDO::OPT_CACHE_HANDLER => 'cache.xPDOAPCCache',
);
$modx->cacheManager->set('testdata', 'My cached data.', 0, $cacheOptions);
echo $modx->cacheManager->get('testdata', $cacheOptions);
// outputs: My cached data.
$modx->cacheManager->delete('testdata', $cacheOptions);
See
http://rtfm.modx.com/display/xPDO20/Caching#Caching-UtilizingSpecificCachePartitions for additional examples of using a custom partition.
That said, If you want the cache to be cleared when the resource cache is flushed, then use the resource partition. Here is the code used by the getCache Add-On, which uses the resource partition by default but allows overrides to all the caching options:
<?php
if (empty($cacheKey)) $cacheKey = $modx->getOption('cache_resource_key', null, 'resource');
if (empty($cacheHandler)) $cacheHandler = $modx->getOption('cache_resource_handler', null, $modx->getOption(xPDO::OPT_CACHE_HANDLER, null, 'xPDOFileCache'));
if (!isset($cacheExpires)) $cacheExpires = (integer) $modx->getOption('cache_resource_expires', null, $modx->getOption(xPDO::OPT_CACHE_EXPIRES, null, 0));
if (empty($cacheElementKey)) $cacheElementKey = $modx->resource->getCacheKey() . '/' . md5($modx->toJSON($properties) . implode('', $modx->request->getParameters()));
$cacheOptions = array(
xPDO::OPT_CACHE_KEY => $cacheKey,
xPDO::OPT_CACHE_HANDLER => $cacheHandler,
xPDO::OPT_CACHE_EXPIRES => $cacheExpires,
);
$cached = $modx->cacheManager->get($cacheElementKey, $cacheOptions);
Otherwise, you will have to use a plugin or other scripted approach to clear your custom provider when users choose Clear Cache in the MODX Manager. FWIW, the above example also adds any custom request parameters to the cache key for instances where you need to cache request specific instances of something.