一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術(shù)及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - PHP教程 - PHP緩存集成庫phpFastCache用法

PHP緩存集成庫phpFastCache用法

2020-08-22 11:37PHP之家 PHP教程

這篇文章主要介紹了PHP緩存集成庫phpFastCache用法,包括基本用法的分析與操作實例,在PHP項目開發(fā)中非常具有實用價值,需要的朋友可以參考下

本文實例講述了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調(diào)用性能

復制代碼 代碼如下:

<?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程序設計有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲国产高清一区二区三区 | 欧美日韩一区二区中文字幕视频 | 亚洲精品国产A久久久久久 亚洲精品福利一区二区在线观看 | 午夜AV国产欧美亚洲高清在线 | 男老头澡堂gay老头456 | 无人影院在线播放视频 | 日韩精品在线一区二区 | 国产欧美视频在线观看 | 欧美日韩看看2015永久免费 | 国产精品色片 | 国产一区风间由美在线观看 | 日韩一区视频在线 | 久久精品久久久久 | 欧美亚洲桃花综合 | 女女同性做爰xxoo亲吻 | 纲手被comic天堂 | 女人全身裸露无遮挡免费观看 | 日韩日b视频 | 美女的隐私脱裤子无遮挡 | 国产传媒在线播放 | 91精品国产91久久久久 | 性xxx免费视频 | 日本一区二区三区精品 | 亚洲香蕉视频 | 四虎国产精品免费久久麻豆 | 国产福利微拍精品一区二区 | 精品一区二区三区在线成人 | 日韩精品视频在线播放 | 性欧美videosex18嫩 | 高清视频在线播放ww | 国产成人咱精品视频免费网站 | 国产亚洲精品网站 | 婷婷精品进入 | 91精品免费观看老司机 | 99精品免费在线观看 | 日本性生活免费看 | 国产91成人精品亚洲精品 | 欧美老肥妇bbb | 3d蒂法精品啪啪一区二区免费 | 欧洲肥女大肥臀tv | 男生操女生动态图 |