gilbitron / php-simplecache
一个简单的PHP脚本,用于缓存第三方API调用。
1.4.2
2017-01-17 12:53 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-14 19:58:39 UTC
README
PHP SimpleCache 类是一种简单的方式来缓存第三方API调用。
安装
通过 composer 安装
{ "require": { "gilbitron/php-simplecache": "~1.4" } }
运行 composer install
然后按正常使用
require 'vendor/autoload.php'; $cache = new Gilbitron\Util\SimpleCache();
用法
一个非常基本的用法示例
$cache = new Gilbitron\Util\SimpleCache(); $latest_tweet = $cache->get_data('tweet', 'http://search.twitter.com/search.atom?q=from:gilbitron&rpp=1'); echo $latest_tweet;
一个更高级的示例
$cache = new Gilbitron\Util\SimpleCache(); $cache->cache_path = 'cache/'; $cache->cache_time = 3600; if($data = $cache->get_cache('label')){ $data = json_decode($data); } else { $data = $cache->do_curl('http://some.api.com/file.json'); $cache->set_cache('label', $data); $data = json_decode($data); } print_r($data);
致谢
PHP SimpleCache 由来自 Gilbert Pellegrom 的 Dev7studios 创建。在MIT许可下发布。