我正在使用此包(https://github.com/spatie/flysystem-dropbox)来存储和从Dropbox获取图像。
这可以正常工作,但是每次刷新页面时都必须加载图像。我想知道您是否知道在这种情况下可以使用的任何图像缓存解决方案,是否可以提供一个最小的工作示例。
谢谢。
解决此问题的一种方法是创建自己的缓存系统。如果本地文件系统上不存在该映像,请将其从Dropbox中拉出,然后将其保存到本地文件系统中并提供服务。如果它已存在于本地文件系统中,则只需从本地文件系统中提供它即可。
根据自己的路线投放图像。
Route::get('images/{filename}', [
'uses' => 'ImageController@getImage'
]);
检查本地文件系统以查看文件是否已存在,否则从Dropbox中将其提取并存储在本地文件系统中。
<?php
namespace App\Http\Controllers;
class ImageController extends Controller
public function __construct()
{
parent::__construct();
}
public function getImage($filename)
{
// If the file doesn't exist
if(!file_exists('/path/to/' . $filename)) {
// 1. Get the image from dropbox
// 2. Save the image to local storage
}
// 3. Serve the image from local storage
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句