infusionweb/laravel-remote-content-cache
Composer 安装命令:
composer require infusionweb/laravel-remote-content-cache
包简介
Provides a Laravel caching package for content retrieved from remote server(s).
README 文档
README
A Laravel package for retrieving and caching content from remote servers.
This package provides a convenient way to retrieve content from remote servers and cache it for use in Laravel.
The assumption is that this process will be used to create a Laravel front-end for a headless CMS setup. However, there are certainly other use cases for which it should work equally well.
Configuration is handled entirely by a single Laravel config file.
Installation
Step 1: Composer
Via Composer command line:
$ composer require infusionweb/laravel-remote-content-cache
Or add the package to your composer.json:
{
"require": {
"infusionweb/laravel-remote-content-cache": "~1.3.1"
}
}
Step 2: Register the Service Provider
Add the service provider to your config/app.php:
'providers' => [ // Kozz\Laravel\Providers\Guzzle::class, InfusionWeb\Laravel\ContentCache\ContentCacheServiceProvider::class, ];
Step 3: Enable the Facade
Add the facade to your config/app.php:
'aliases' => [ // 'Guzzle' => Kozz\Laravel\Facades\Guzzle::class, 'ContentCache' => InfusionWeb\Laravel\ContentCache\ContentCacheFacade::class, ];
Step 4: Publish the package config file
$ php artisan vendor:publish --provider="InfusionWeb\Laravel\ContentCache\ContentCacheServiceProvider"
You may now configure remote API endpoints for consumption and other preferences by editing the config/contentcache.php file.
Step 5: Enable the Artisan Console Command
Add the command to your app/Console/Kernel.php:
protected $commands = [ // \InfusionWeb\Laravel\ContentCache\ContentCacheCommand::class, ];
This enables the console command which can be used to periodically cache the remote content in Laravel:
$ php artisan content:cache
The previous command will cache all configured content types, whereas the following command will cache only the "podcasts" type (assuming it is defined in contentcache.php).
$ php artisan content:cache podcasts
Usage Example
Assuming that a content type "podcasts" is defined in the config/contentcache.php file:
<?php return [ /* * Default configuration. */ 'default' => [ // Default length of time (in minutes) to cache content. 'minutes' => 60, ], /* * Configuration for custom content filters. */ 'podcasts' => [ // Length of time (in minutes) to cache content. 'minutes' => 60 * 3, // 3 hours // REST API endpoint for service from which to retrieve content. 'endpoint' => 'https://podcasts.example.com/api/v1/content/podcasts', 'query' => ['_format' => 'json'], // Perform data filter (value) on given field name (key). So in this // case, "id" and "episode" will be cast as integers, and "date_created" // and "date_changed" will be cast as Carbon date objects. All other // values will be cast as strings. 'filters' => [ 'id' => 'int', 'date_created' => 'date', 'date_changed' => 'date', 'episode' => 'int', ], // New fields to be created on cached content object from given field names. // E.g. Given an "episode" value of 13 and a "title" of "Lucky 13", the // new "slug" attribute (useful for use in routes) will have a value of // "13-lucky-13". 'fields' => [ 'slug' => ['episode', 'title'], ], // Keys by which the cache should be indexed. I.e. each content // object will be cached under each of these index keys. 'keys' => [ 'id', 'slug', 'uuid', 'episode', ], ], ];
The following code can be used to cache and retrieve podcast content:
<?php use ContentCache; // Manually cache remote podcast episodes, if this process is not handled via the // Artisan console command. ContentCache::profile('podcasts')->cache(); // Then retrieve a list of all episodes. $episodes = ContentCache::profile('podcasts')->getAll(); // This could also be shortened to: $episodes = ContentCache::profile('podcasts')->cache()->getAll(); // Individual content objects can be retrieved via configured indexes. // In this case, by ID. $episode = ContentCache::profile('podcasts')->getBy('id', 13); // Or by slug (from a Laravel Request object), using the "magic function". $cache = ContentCache::profile('podcasts'); $episode = $cache->getBySlug('13-lucky-13'); // This makes it easy to hand off to a Blade template. return view('pages.podcast.episode', compact('episode'));
Credits
License
The MIT License (MIT). Please see License File for more information.
infusionweb/laravel-remote-content-cache 适用场景与选型建议
infusionweb/laravel-remote-content-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.75k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「remote」 「content」 「laravel」 「headless cms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 infusionweb/laravel-remote-content-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 infusionweb/laravel-remote-content-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 infusionweb/laravel-remote-content-cache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Allow packages to be installed from a repository or tarball bundle that have multiple packages in the sub-folders
A block that displays featured content - large image, title, description and link.
PHP library that allows linking queries from diferent physical databases using mysql pdo database connections
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 13.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-10