因此,例如在您的控制器中:
/**
* Remove an image in the cache based on its relative path and the filter applied to it
*
* @param string $path
* @param string $filter
*
* @return void
*/
protected function removeCachedImageAction($path, $filter)
{
$cacheManager = $this->container->get('liip_imagine.cache.manager');
// Remove the cached image corresponding to that path & filter, if it is stored
if ($cacheManager->isStored($path, $filter)) {
$cacheManager->remove($path, $filter);
}
}
/**
* An action that doesn't do much except testing the function above
*
* @param Request $request
*
* @return void
*/
protected function whateverAction(Request $request)
{
$path = //... probably from the request
$filter = //... probably from the request
// Remove the cached image
$this->removeCachedImage($path, $filter);
// ...
}
正如您在CacheManager中看到的,您想要使用的功能是:
public function remove($paths = null, $filters = null){ ... }
如果$paths
是null
,则该函数假定您要删除已使用提供的所有 PATHS$filters
解析的缓存图像。
如果$filters
是null
,该函数假定您要删除与所$paths
提供的对应的缓存图像,并且之前已使用ALL FILTERS解决了这些图像。
如果$paths
和$filters
是null
,该函数假定您要删除对应于 ALL PATHS 和 ALL FILTERS 的缓存图像。基本上所有缓存的图像。