mitogh/on-cache-please
Composer 安装命令:
composer require mitogh/on-cache-please
包简介
Storage a request automatically on a transient cache
关键字:
README 文档
README
Because programmers are to lazy to write repeated code, this utility automatically storages the data of a callback in a transient to faster access the next time the data is accessed.
Description
This utility can help you to create faster cache storage of expensive external request or hard work into the DB to faster access the next time, to retrive the value from a cache rather than the function, this library make uses of transient api to save the data from the requests into the DB.
Requirements.
- WordPress
- PHP 5.4 >=
Installation.
The easiest way to install this library is using composer, in order to add this library as a dependency for your composer file you only need to run in your terminal:
composer require mitogh/on-cache-please
To retrive the library from packagist. This will
add the on-cache-please library as a dependency in your composer.json
file.
The other way is directly include the file:
include 'On-Cache-Please/src/OnCache.php';
Into your functions.php file in your theme or in your plugin.
Methods and Properties
Here are listed only the public methods that are available to be used from the outside of the library.
OnCache::please
This static method is the public way to storaged the data from a function in a transient by a determined amount of time in order to decrease the number of request and download time.
Parameters
You can pass an array of arguments to the method please in order to
update some default values and some required params as well.
name(string) - required. This is a required param since we need a value to identify the transient, where the data is going to be stored.callback(string|function) - required. The function or name of the function to execute, in this function you can do expensive things like an http external request or a instagram API call, just make sure to return the data you want to save on the cache, the returned value will be storead in the transient.duration(int) - optional. 1 hour by default. This value can be any integer number and represents the life of the transient in seconds before execute thecallbackagain and update the transient, there are few few already defined. constants that migh help you.
Example
In this example we retrieve the data from http://codepen.io/jobs.json
and store the result in a transient that has a duration (by default of 1
hour), so the next hour we are going to have the latest updated data
wiouth having to make a request every time the page is loaded.
Library installed via composer.json
include './vendor/autoload.php'; $args = array( 'name' => 'codepen_jobs', 'callback' => function(){ $url = 'http://codepen.io/jobs.json'; return wp_remote_retrieve_body( wp_remote_get( $url ) ); }, ); $jobs = mitogh\OnCache::please( $args );
Library installed manually:
include './On-Cache-Please/src/OnCache.php'; $args = array( 'name' => 'codepen_jobs', 'callback' => function(){ $url = 'http://codepen.io/jobs.json'; return wp_remote_retrieve_body( wp_remote_get( $url ) ); }, ); $jobs = mitogh\OnCache::please( $args );
mitogh/on-cache-please 适用场景与选型建议
mitogh/on-cache-please 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「wordpress」 「request」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mitogh/on-cache-please 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mitogh/on-cache-please 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mitogh/on-cache-please 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
HTTP request logger middleware for Laravel
Laravel 5 - Repositories to the database layer
Adds request-parameter validation to the SLIM 3.x PHP framework
Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
A simple HTTP application builder using PSR-15 HTTP Server Request Handler and Middleware.
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-27