biigle/laravel-file-cache 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

biigle/laravel-file-cache

Composer 安装命令:

composer require biigle/laravel-file-cache

包简介

Fetch and cache files from local filesystem, cloud storage or public webservers in Laravel

README 文档

README

Fetch and cache files from local filesystem, cloud storage or public webservers in Laravel or Lumen.

The file cache is specifically designed for use in concurrent processing with multiple parallel queue workers and lots of files.

Tests

Installation

composer require biigle/laravel-file-cache

Laravel

The service provider and FileCache facade are auto-discovered by Laravel.

Lumen

Add this to bootstrap/app.php:

$app->register(Biigle\FileCache\FileCacheServiceProvider::class);
$app->register(Illuminate\Filesystem\FilesystemServiceProvider::class);

To use the FileCache facade, enable $app->withFacades() and add the following to bootstrap/app.php:

if (!class_exists(FileCache::class)) {
    class_alias(Biigle\FileCache\Facades\FileCache::class, 'FileCache');
}

Without facades, the file cache instance is available as app('file-cache').

Usage

Take a look at the FileCache contract to see the public API of the file cache. Example:

use FileCache;
use Biigle\FileCache\GenericFile;

// Implements Biigle\FileCache\Contracts\File.
$file = new GenericFile('https://example.com/images/image.jpg');

FileCache::get($file, function ($file, $path) {
    // do stuff
});

If the file URL specifies another protocol than http or https (e.g. mydisk://images/image.jpg), the file cache looks for the file in the appropriate storage disk configured at filesystems.disks. You can not use a local file path as URL (e.g. /vol/images/image.jpg). Instead, configure a storage disk with the local driver.

Configuration

The file cache comes with a sensible default configuration. You can override it in the file-cache namespace or with environment variables.

file-cache.max_file_size

Default: -1 (any size) Environment: FILE_CACHE_MAX_FILE_SIZE

Maximum allowed size of a cached file in bytes. Set to -1 to allow any size.

file-cache.max_age

Default: 60 Environment: FILE_CACHE_MAX_AGE

Maximum age in minutes of a file in the cache. Older files are pruned.

file-cache.max_size

Default: 1E+9 (1 GB) Environment: FILE_CACHE_MAX_SIZE

Maximum size (soft limit) of the file cache in bytes. If the cache exceeds this size, old files are pruned.

file-cache.path

Default: 'storage/framework/cache/files'

Directory to use for the file cache.

file-cache.timeout

Default: 5.0 Environment: FILE_CACHE_TIMEOUT

Read timeout in seconds for fetching remote files. If the stream transmits no data for longer than this period (or cannot be established), caching the file fails.

file-cache.prune_interval

Default '*/5 * * * *' (every five minutes)

Interval for the scheduled task to prune the file cache.

file-cache.mime_types

Default: [] (allow all types)

Array of allowed MIME types for cached files. Caching of files with other types will fail.

Clearing

The file cache is cleared when you call php artisan cache:clear.

Testing

The FileCache facade provides a fake for easy testing. The fake does not actually fetch and store any files, but only executes the callback function with a faked file path.

use FileCache;
use Biigle\FileCache\GenericFile;

FileCache::fake();
$file = new GenericFile('https://example.com/image.jpg');
$path = FileCache::get($file, function ($file, $path) {
    return $path;
});

$this->assertFalse($this->app['files']->exists($path));

biigle/laravel-file-cache 适用场景与选型建议

biigle/laravel-file-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36.85k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2019 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 biigle/laravel-file-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 biigle/laravel-file-cache 我们能提供哪些服务?
定制开发 / 二次开发

基于 biigle/laravel-file-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 36.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 22
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-05