首页 >

PHP缓存集成库phpFastCache用法

php教程|php手册PHP缓存集成库phpFastCache用法
PHP,缓存,集成库,phpFastCache,用法
php教程-php手册
小额贷款app源码,vscode ssh使用,ubuntu局域网聊天,tomcat 代码审计,sqlite-jdbc,香港 服务器托管 哪一家比较好,生成二维码插件,纯前端搭建框架,php 比较好的爬虫框架,学习php之前,深圳seo优化排名推广,课程教学网站模板,qq浏览器修改网页源码,企业psd模板,运行商品信息添加页面代码显示系统错误,仓库管理系统sql vb,淘宝客模板程序lzw
这篇文章主要介绍了PHP缓存集成库phpFastCache用法,包括基本用法的分析与操作实例,在PHP项目开发中非常具有实用价值,需要的朋友可以参考下
ssm整合项目源码,vscode更改文件编码,ubuntu dell,tomcat 开机自启动,sqlite3啥意思,优秀个人网页设计欣赏,wdcp 数据库地址,网站服务器选购,jquery自定义插件模板,前端工作流框架vue,迷路的小爬虫,PHP dir,学seo网站优化,springboot启动教程,dede导航标签调用,红酒网站程序,网页无限下滚怎么翻页,软件使用说明书模板 下载,家具网站后台模板,扁平化页面布局,员工日志管理系统,c 游戏程序lzw
程序化交易源码的中文说明,vscode怎么改英文输出,ubuntu指令ls,tomcat登录失败处理,导入爬虫包,php社交网站源码,龙华seo关键词优化价格lzw

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


PHP缓存集成库phpFastCache用法
  • PHP缓存库phpFastCache
  • PHP缓存库phpFastCache | PHP缓存库phpFastCache ...

    PHP缓存集成库phpFastCache用法
  • PHP缓存集成库phpFastCache用法【PHP】
  • PHP缓存集成库phpFastCache用法【PHP】 | PHP缓存集成库phpFastCache用法【PHP】 ...

    PHP缓存集成库phpFastCache用法
  • 关于PHP缓存库phpFastCache的使用
  • 关于PHP缓存库phpFastCache的使用 | 关于PHP缓存库phpFastCache的使用 ...