在图像干预中使用缓存和克隆而不只使用克隆好吗?
我想制作不同尺寸的图像。缓存文件并克隆它以生成不同的尺寸,这很好吗?或者,如果我只使用克隆(没有缓存),没有什么不同?
没有缓存:
$image->make($this->file);
使用缓存:
$image = Image::cache(function($image) {
$image->make($this->file);
});
生成不同的尺寸:
for($sizes as $size) {
$clonedImage = clone $image;
// Generate different sizes of that image...
}
I want to make different sizes of an image. Is it good to cache the file and clone it for generating different sizes? Or no different if I use only clone (without cache)?
Without cache:
$image->make($this->file);
With cache:
$image = Image::cache(function($image) {
$image->make($this->file);
});
Generate different sizes:
for($sizes as $size) {
$clonedImage = clone $image;
// Generate different sizes of that image...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
生成不同的尺寸与缓存图像无关。
Image :: CACHE
将使用您的Laravel项目的默认缓存驱动程序。当您想使用Image :: Cache
检索图像时,它将检查是否在缓存(hit)中可用(hist)(遗漏)。当可用的情况下,操作将很快,并且如果不是,则需要一些时间,具体取决于负责构建要缓存数据的业务逻辑。您将需要在 中在
中生成的每个大小。我还建议使用 Glide ,它只会使您的生活更轻松,因为它可以自动处理缓存,您可以使您的生活更加轻松通过HTTP操纵图像。
Generating different sizes has nothing to do with caching the image.
Image::cache
will use your the default cache driver of your Laravel project. When you want to retrieve an image usingImage::cache
, it will check if it's available in the cache (hit) or not (miss). When it's available, the operation will be fast and when it's not, it will take some time depending on the business logic that is responsible of building the data to be cached.You will need to cache every single size you generate in the
for loop
you wrote. I would also suggest using glide, it will just make your life easier as it handles cache automatically and you can manipulate images on-the-go over HTTP.