1

当源图像被删除或更新时,我正在尝试删除缓存的图像(使用 LiipImagineBundle 创建)。我已经发现它可以使用 CacheManager ( https://github.com/liip/LiipImagineBundle/issues/132 ) 来完成。问题是我无法弄清楚如何准确地使用它。尽管有这三行,我还需要在代码中添加什么(如库):

    $cacheManager = $this->get('liip_imagine.cache.manager');
    $cacheManager->resolve($this->getRequest(),$pngPath,$filter);
    $cacheManager->remove($pngPath, $filter);

我相信应该有类似的东西

    $cacheManager = new CacheManager();

如果有人能更详细地解释我如何做到这一点,我将不胜感激。

4

1 回答 1

1

因此,例如在您的控制器中:

/**
* 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){ ... }
  • 如果$pathsnull,则该函数假定您要删除已使用提供的所有 PATHS$filters解析的缓存图像。

  • 如果$filtersnull,该函数假定您要删除与所$paths提供的对应的缓存图像,并且之前已使用ALL FILTERS解决了这些图像。

  • 如果$paths$filtersnull,该函数假定您要删除对应于 ALL PATHS 和 ALL FILTERS 的缓存图像。基本上所有缓存的图像。

于 2014-09-19T06:13:48.640 回答