介绍
今天就跟大家聊聊有关phpFastCache怎么在PHP项目中使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
phpFastCache是一个开源的PHP缓存库,只提供一个简单的PHP文件,可方便集成到已有项目,支持多种缓存方法,包括:apc, memcache, memcached, wincache,文件,pdo和mpdo。可通过简单的API来定义缓存的有效时间。
& lt; ? PHP//,拷贝your config fileinclude (“phpFastCache/phpfastcache.php"); phpFastCache:设置(“storage",“auto");//,phpFastCache support “apc",,“memcache",,“memcached",,“wincache",,“files",,“sqlite",以及“xcache"//,你不要# 39;t need 用change your code when 你change your caching 系统只趁机simple keep it 汽车cache 美元;=,phpFastCache ();//,your 类,函数,拷贝,PHP //页面,try 用get 得到Cache 第一只product_page =, your Identity 关键字products 美元;=,缓存→美元(“product_page"); if ($ products ==, null), {,,, products 美元;=,YOUR DB QUERIES | |, GET_PRODUCTS_FUNCTION;,,,,//, set products 拷贝用cache 拷贝;600年,seconds =, 10, minutes ,,,美元缓存→设置(“product_page",,美元的产品,600);}//,Output Your Contents  products 美元;这里
<>强提高旋度和API调用性能强> <强>
强>
cache 美元;=,phpFastCache (“memcached");//,try 用get 得到Cache 第一。results 美元;=,缓存→美元得到(“identity_keyword") if ($ results ==, null), {,,, results 美元;=,旋度→(“http://www.youtube.com/api/json/url/keyword/page"),,,,,//, Write 用Cache 节省;API Calls next time ,,,美元缓存→设置(“identity_keyword",,结果,美元,3600 * 24);} foreach ($ results as $视频),{,,,//,Output Your Contents 这里}
<强>全页缓存
强>
& lt; ? php//, use Files Cache for Whole Page /小部件=//,keyword Webpage_URL keyword_webpage 美元;=,md5 ($ _SERVER [& # 39; HTTP_HOST& # 39;]。$ _SERVER [& # 39; REQUEST_URI& # 39;]。$ _SERVER [& # 39; QUERY_STRING& # 39;]); html 美元;=,估计(“files")→(keyword_webpage美元); if ($ html ==, null), {,,, ob_start (),,,,,/*,,,,,,,, ALL OF YOUR CODE GO HERE ,,,,,,, RENDER YOUR 页面,DB 查询,,WHATEVER ,,, */,,,//,GET HTML WEBPAGE ,,, HTML 美元;=,ob_get_contents(),,,,,//,节省;用Cache 30, minutes ,,,估计(“files")→设置(keyword_webpage, html,美元,1800);} echo 美元html;
<强>挂件缓存
强>
& lt; php ?//,use Files Cache  for Whole Page /,部件Cache 美元;=,phpFastCache (“files"); 美元$ html =,缓存→widget_1; if ($ html ==, null), {,,, html 美元;=,Render Your Page | |, Widget | |,“Hello World",,,,,//,节省;用Cache 30, minutes ,,,缓存→美元widget_1 =,数组(html、美元,1800);} return  echo ,或是;your html美元;
<强>同时使用多种缓存
强>
& lt; php ?//,拷贝your config  filesinclude (“phpfastcache/phpfastcache.php");//, auto |, memcache |, files 等只Will be default for cache 美元;=,估计();phpfastcache:: $ storage =,“auto"; $ cache1 =, phpFastCache (); $ cache2 =,估计(“memcache"); server 美元;=,数组(数组(“127.0.0.1"、11211、100),,数组(“128.5.1.3"、11215、80));美元cache2→选项(“server",,美元服务器); $ cache3 =, new phpFastCache (“apc");//,,请用写?美元cache1→设置(“keyword1",,“字符串|数字数组| | object",, 300);美元cache2→keyword2 =,数组(“something  here",, 600);估计()→keyword3 =,数组(“数组| object",, 3600 * 24); null null null null null null null null nullphpFastCache怎么在PHP项目中使用