PHP缓存库phpFastCache
phpFastCache是一个开源的PHP缓存库,只提供一个简单的PHP文件,可方便集成到已有项目,支持多种缓存方法,包括:apc, memcache, memcached, wincache, files, pdo and mpdo。可通过简单的API来定义缓存的有效时间。
减少数据库查询
<?php
// In your config file
include("phpfastcache/phpfastcache.php");
phpFastCache::setup("storage","auto"); // phpFastCache support "apc", "memcache", "memcached", "wincache" ,"files", "sqlite" and "xcache"
// You don't need to change your code when you change your caching system. Or simple keep it auto
$cache = phpFastCache(); // In your Class, Functions, PHP Pages
// try to get from Cache first. product_page = YOUR Identity Keyword
$products = $cache->get("product_page"); if($products == null) {
$products = YOUR DB QUERIES || GET_PRODUCTS_FUNCTION;
// set products in to cache in 600 seconds = 10 minutes
$cache->set("product_page", $products,600);
} // Output Your Contents $products HERE
提高cURL和API调用性能
<?php
include("phpfastcache/phpfastcache.php"); $cache = phpFastCache("memcached"); // try to get from Cache first.
$results = $cache->get("identity_keyword") if($results == null) {
$results = cURL->get("http://www.youtube.com/api/json/url/keyword/page");
// Write to Cache Save API Calls next time
$cache->set("identity_keyword", $results, 3600*24);
} foreach($results as $video) {
// Output Your Contents HERE
}
全页缓存
<?php
// use Files Cache for Whole Page / Widget // keyword = Webpage_URL
$keyword_webpage = md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING']);
$html = __c("files")->get($keyword_webpage); if($html == null) {
ob_start();
/*
ALL OF YOUR CODE GO HERE
RENDER YOUR PAGE, DB QUERY, WHATEVER
*/ // GET HTML WEBPAGE
$html = ob_get_contents();
// Save to Cache 30 minutes
__c("files")->set($keyword_webpage,$html, 1800);
} echo $html;
挂件缓存
<?php
// use Files Cache for Whole Page / Widget
$cache = phpFastCache("files"); $html = $cache->widget_1; if($html == null) {
$html = Render Your Page || Widget || "Hello World";
// Save to Cache 30 minutes
$cache->widget_1 = array($html, 1800);
} echo or return your $html;
同时使用多种缓存
<?php
// in your config files
include("phpfastcache/phpfastcache.php");
// auto | memcache | files ...etc. Will be default for $cache = __c();
phpFastCache::$storage = "auto"; $cache1 = phpFastCache(); $cache2 = __c("memcache");
$server = array(array("127.0.0.1",11211,100), array("128.5.1.3",11215,80));
$cache2->option("server", $server); $cache3 = new phpFastCache("apc"); // How to Write?
$cache1->set("keyword1", "string|number|array|object", 300);
$cache2->keyword2 = array("something here", 600);
__c()->keyword3 = array("array|object", 3600*24); // How to Read?
$data = $cache1->get("keyword1");
$data = $cache2->keyword2;
$data = __c()->keyword3;
$data = __c()->get("keyword4"); // Free to Travel between any caching methods $cache1 = phpFastCache("files");
$cache1->set("keyword1", $value, $time);
$cache1->memcache->set("keyword1", $value, $time);
$cache1->apc->set("whatever", $value, 300); $cache2 = __c("apc");
$cache2->keyword1 = array("so cool", 300);
$cache2->files->keyword1 = array("Oh yeah!", 600); $data = __c("memcache")->get("keyword1");
$data = __c("files")->get("keyword2");
$data = __c()->keyword3; // Multiple ? No Problem $list = $cache1->getMulti(array("key1","key2","key3"));
$cache2->setMulti(array("key1","value1", 300),
array("key2","value2", 600),
array("key3","value3", 1800),
); $list = $cache1->apc->getMulti(array("key1","key2","key3"));
__c()->memcache->getMulti(array("a","b","c")); // want more? Check out document in source code
以上demo来自官网示例。
官网地址:http://www.phpfastcache.com/
PHP缓存库phpFastCache的更多相关文章
- picasso-强大的Android图片下载缓存库
编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! pica ...
- 基于memcached的单机轻量级通用缓存库minicached的实现
一.前言 之前拜读过淘宝子柳的<淘宝技术这十年>之大作,深知缓存技术在系统优化中起着一个举足轻重的作用.无论是文件系统静态文件,数据库的访问,乃至网络数据的请求,只要是与内存访问速度相差较 ...
- picasso_强大的Android图片下载缓存库
tag: android pic skill date: 2016/07/09 title: picasso-强大的Android图片下载缓存库 [本文转载自:泡在网上的日子 参考:http://bl ...
- 高性能 Java 缓存库 — Caffeine
http://www.baeldung.com/java-caching-caffeine 作者:baeldung 译者:oopsguy.com 1.介绍 在本文中,我们来看看 Caffeine - ...
- 毕加索的艺术——Picasso,一个强大的Android图片下载缓存库,OkHttpUtils的使用,二次封装PicassoUtils实现微信精选
毕加索的艺术--Picasso,一个强大的Android图片下载缓存库,OkHttpUtils的使用,二次封装PicassoUtils实现微信精选 官网: http://square.github.i ...
- android-------非常好的图片加载框架和缓存库(Picasso)
Picasso是Square公司开源的一个Android图形缓存库, 可以实现图片加载(本地和网络)和缓存功能. 地址:http://square.github.io/picasso/ jar包下载: ...
- 轻量级UIImageView分类缓存 库 AsyncImageView 使用
轻量级UIImageView分类缓存 库 AsyncImageView 使用 一: AsyncImageView 主页:https://github.com/nicklockwood/AsyncIma ...
- android开源项目:图片下载缓存库picasso
picasso是Square公司开源的一个Android图形缓存库,地址http://square.github.io/picasso/,可以实现图片下载和缓存功能. picasso有如下特性: 在a ...
- (源代码分析)Android-Universal-Image-Loader (图片异步载入缓存库)的使用配置
转载请注明出处:http://blog.csdn.net/u011733020 前言: 在Android开发中,对于图片的载入能够说是个老生常谈的问题了,图片载入是一个比較坑的地方.处理不好,会有各种 ...
随机推荐
- 创建Pods私有库
Pods私有库创建步骤 创建私有 Spec Repo 创建Pod项目工程文件 创建podspec文件 本地测试podsspec文件 向Spec Repo提交podspec Pod库使用 更新维护pos ...
- day03_雷神_文件操作
day03 上周回顾_问题总结: 地址值: li = [] name = ['name','price','count'] dic = {} #如果这里定义空列表,后边的dic[name[i]] = ...
- 5.css背景以及书写位置
1.样式表书写位置 ◆内嵌式写法 <head> <style type=”text/css”> 样式表写法 </style> </head> 2.◆外链 ...
- 第21件事 资源支持离不开RACI表
十步法的第九步寻求资源支持.资源主要包括人力资源.物力资源和财力资源.人力资源,即需要多少人:物力资源,即需要多少软硬件设备:财力资源,即需要多少预算.根据产品或项目目标,资源估算时要考虑需要什么样的 ...
- .NET Core下开源任务调度框架Hangfire的Api任务拓展(支持秒级任务)
HangFire的拓展和使用 看了很多博客,小白第一次写博客. 最近由于之前的任务调度框架总出现问题,因此想寻找一个替代品,之前使用的是Quartz.Net,这个框架方便之处就是支持cron表达式适合 ...
- oracle查询语句查询增加一列内容
select a,sys_guid() as b from mytable sys_guid() 是生成带分隔符(-)的GUID的自定义函数 查询B表的内容插入A表,MY_ID是A表的主键不可为空,因 ...
- wpf根据X与Y轴获取内部值
效果图: 环境 Visual Studio ,.Net Framework 4.0 SDK 支持Windows XP,Windows Win7.. 实现方法: 创建ListBox设置ListBox.I ...
- Dapper实现一对多对象关系聚合导航属性
领域对象:Game(游戏), Room(游戏群),两者一对多的关系,SQL语句中会用到JOIN public class Game : AggregateRoot { public string Ta ...
- Linq to xml修改CDATA节点值
增加节点时,我们是这样写的: xop.Document.Element("messages").Add( new XElement("message", new ...
- Liferay开发实战(2):Service Builder生成持久化层,及开发服务层
本文Liferay适用版本:v6.2.ce-ga6版 Liferay的插件体系是:模型-视图-控制器的portlet MVC框架.MVC是一个伟大的用于Web应用程序的设计模式,在实际应用中还应处理持 ...