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的更多相关文章

  1. picasso-强大的Android图片下载缓存库

    编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! pica ...

  2. 基于memcached的单机轻量级通用缓存库minicached的实现

    一.前言 之前拜读过淘宝子柳的<淘宝技术这十年>之大作,深知缓存技术在系统优化中起着一个举足轻重的作用.无论是文件系统静态文件,数据库的访问,乃至网络数据的请求,只要是与内存访问速度相差较 ...

  3. picasso_强大的Android图片下载缓存库

    tag: android pic skill date: 2016/07/09 title: picasso-强大的Android图片下载缓存库 [本文转载自:泡在网上的日子 参考:http://bl ...

  4. 高性能 Java 缓存库 — Caffeine

    http://www.baeldung.com/java-caching-caffeine 作者:baeldung 译者:oopsguy.com 1.介绍 在本文中,我们来看看 Caffeine - ...

  5. 毕加索的艺术——Picasso,一个强大的Android图片下载缓存库,OkHttpUtils的使用,二次封装PicassoUtils实现微信精选

    毕加索的艺术--Picasso,一个强大的Android图片下载缓存库,OkHttpUtils的使用,二次封装PicassoUtils实现微信精选 官网: http://square.github.i ...

  6. android-------非常好的图片加载框架和缓存库(Picasso)

    Picasso是Square公司开源的一个Android图形缓存库, 可以实现图片加载(本地和网络)和缓存功能. 地址:http://square.github.io/picasso/ jar包下载: ...

  7. 轻量级UIImageView分类缓存 库 AsyncImageView 使用

    轻量级UIImageView分类缓存 库 AsyncImageView 使用 一: AsyncImageView 主页:https://github.com/nicklockwood/AsyncIma ...

  8. android开源项目:图片下载缓存库picasso

    picasso是Square公司开源的一个Android图形缓存库,地址http://square.github.io/picasso/,可以实现图片下载和缓存功能. picasso有如下特性: 在a ...

  9. (源代码分析)Android-Universal-Image-Loader (图片异步载入缓存库)的使用配置

    转载请注明出处:http://blog.csdn.net/u011733020 前言: 在Android开发中,对于图片的载入能够说是个老生常谈的问题了,图片载入是一个比較坑的地方.处理不好,会有各种 ...

随机推荐

  1. bootstrap 图片切换

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  2. 如何处理由Dll缺失造成的程序直接崩溃的问题。

    问题描述:在开发一个上位机程序时(C#.winform),使用到了Kvaser的SDK,而这个SDK是基于对应的Kvaser驱动开发的.当前PC如果没有装Kvaser驱动, 程序启动时,会直接奔溃.调 ...

  3. MCU_数码管常用表

    共阴极数码管编码(0---F) unsigned char code table[]={ 0x3f,0x06,0x5d,0x4f, 0x66,0x6d,0x77,0x7c, 0x39,0x5e,0x7 ...

  4. 关于使用java自动发邮件--找不到smtphost

    今天解决报的第二个异常:Unknown SMTP host: smtp.qq.com;在找了网上的一些资料后,有看到是因为使用了代理服务器,所以无法访问.我试着用了telnet去访问,确实不行.最近都 ...

  5. ASP.NET Core 2.1 源码学习之 Options[3]:IOptionsMonitor

    前面我们讲到 IOptions 和 IOptionsSnapshot,他们两个最大的区别便是前者注册的是单例模式,后者注册的是 Scope 模式.而 IOptionsMonitor 则要求配置源必须是 ...

  6. KNIME + Python = 数据分析+报表全流程

    Python 数据分析环境 数据分析领域有很多可选方案,例如SPSS傻瓜式分析工具,SAS专业性商业分析工具,R和python这类需要代码编程类的工具.个人选择是python这类,包括pandas,n ...

  7. Alwasyon环境下增加数据文件需要注意的几点

    半夜收到报警短信,服务器磁盘空间不足,爬起来检查一番,发现由于索引重建导致,而且该磁盘下仍有自动增长的数据文件,由于该服务器上其他盘符有剩余空间,于是打算将该磁盘下的数据文件限制增长,并新增几个数据文 ...

  8. 【抄袭】VB.NET扩展WebBrowser,拥有跳转前获取URL的能力

    来自 http://www.cnblogs.com/yuanjw/archive/2009/02/09/1386789.html 我仅做VB化,并优化了事件消息 Imports System.Comp ...

  9. nginx windown命令

    cmd进入nginx程序文件夹启动nginx:start nginx nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx nginx -t ...

  10. 为什么主流的 App 看起来都差不多?这可能是件好事

    欢迎访问网易云社区,了解更多网易技术产品运营经验. 现在设计师可以把精力都花在真正有意义的地方了. 打开Instagram.Airbnb.Apple Music.Twitter.Dropbox或Lyf ...