dqudtskm49788 2014-10-13 08:15
浏览 492

使用带有Laravel的Intervention / ImageCache清除图像所有操作的缓存

I'm trying to work out a way to clear the cache of all manipulations of an image that have been created using Intervention/ImageCache's manipulation templates (and likely in the future the cache function as well).

I have a some manipulation templates that run a custom filters on the image:

'thumbnail' => function($image) {
    return $image->filter(new ImageFilters\Fit(150));
},

The filter gets the focal point from the database and then runs the appropriate functions, using the focal point for the position as needed.

public function applyFilter(Image $image)
{
    $fp = Media::where('file_name', $image->filename)->pluck('focal_point');
    $fp = $fp ?: 'center';
    return $image->fit($this->width, $this->height, function(){return true;}, $fp);
}

This all works fine, but when the focal point is changed by the user the image isn't updated because of the cache. I need a way of clearing the cache for that specific image across the board.

From what I can tell each manipulated image is given its own unique cache key made up of an md5 hash, but I can't find any way of targeting all manipulations of a single image.

  • 写回答

2条回答 默认 最新

  • dowy77780 2014-11-15 19:03
    关注

    Clearing the cache for one image is not possible. The string for the focal_point must be in the callback signature, to take effect on the caching.

    You can do this, by adding it to the Filter, by GET parameter for example.

    'thumbnail' => function($image) {
        $fp = Input::get('fp', 'center');
        return $image->filter(new ImageFilters\Fit(150, $fp));
    },
    

    Then request your image like this:

    /imagecache/thumbnail/foo.jpg?fp=center
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘