最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP緩存集成庫phpFastCache用法

 更新時間:2014年12月15日 12:34:05   投稿:shichen2014  
這篇文章主要介紹了PHP緩存集成庫phpFastCache用法,包括基本用法的分析與操作實(shí)例,在PHP項(xiàng)目開發(fā)中非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了PHP緩存集成庫phpFastCache用法。分享給大家供大家參考。具體分析如下:

phpFastCache是一個開源的PHP緩存庫,只提供一個簡單的PHP文件,可方便集成到已有項(xiàng)目,支持多種緩存方法,包括:apc, memcache, memcached, wincache, files, pdo and mpdo??赏ㄟ^簡單的API來定義緩存的有效時間。

復(fù)制代碼 代碼如下:
<?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)用性能
復(fù)制代碼 代碼如下:
<?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
}

全頁緩存

復(fù)制代碼 代碼如下:
<?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;

掛件緩存

復(fù)制代碼 代碼如下:
<?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;

同時使用多種緩存

復(fù)制代碼 代碼如下:
<?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程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • php中簡單的對稱加密算法實(shí)現(xiàn)

    php中簡單的對稱加密算法實(shí)現(xiàn)

    最近突發(fā)奇想要往數(shù)據(jù)庫里保存一些機(jī)密的東西,然后就想著怎么讓別人即使進(jìn)入到了數(shù)據(jù)庫也看不懂存儲的是什么,那么只有加密了;可是我們自己還要看呢,那只能找一些對稱加密的算法了,我們想看的時候再解密回來。下面就介紹了php中簡單的對稱加密算法實(shí)現(xiàn)。
    2017-01-01
  • PHP隨機(jī)數(shù) C擴(kuò)展隨機(jī)數(shù)

    PHP隨機(jī)數(shù) C擴(kuò)展隨機(jī)數(shù)

    這篇文章主要介紹了PHP隨機(jī)數(shù),C擴(kuò)展隨機(jī)數(shù)的相關(guān)資料,還為大家介紹了PHP唯一ID生成擴(kuò)展ukey,感興趣的小伙伴們可以參考一下
    2016-05-05
  • PHP eval函數(shù)使用介紹

    PHP eval函數(shù)使用介紹

    eval()函數(shù)中的eval是evaluate的簡稱,這個函數(shù)的作用就是把一段字符串當(dāng)作PHP語句來執(zhí)行,一般情況下不建議使用容易被黑客利用
    2013-12-12
  • PHP讀取TXT文本內(nèi)容的五種實(shí)用方法小結(jié)

    PHP讀取TXT文本內(nèi)容的五種實(shí)用方法小結(jié)

    PHP作為一種流行的服務(wù)器端腳本語言,提供了多種方法來讀取TXT文本內(nèi)容,本文主要為大家詳細(xì)介紹五種不同的PHP方法,希望對大家有所幫助
    2024-01-01
  • php類常量用法實(shí)例分析

    php類常量用法實(shí)例分析

    這篇文章主要介紹了php類常量用法,實(shí)例分析了php中類常量的概念、特性與相關(guān)使用技巧,需要的朋友可以參考下
    2015-07-07
  • 幾個優(yōu)化WordPress中JavaScript加載體驗(yàn)的插件介紹

    幾個優(yōu)化WordPress中JavaScript加載體驗(yàn)的插件介紹

    這篇文章主要介紹了幾個優(yōu)化WordPress中JavaScript加載體驗(yàn)的插件,一般來說在WordPress中加載JavaScript最好使用wp_enqueue_script()函數(shù)以減少問題提高效率,需要的朋友可以參考下
    2015-12-12
  • php操作redis的常見用法詳解

    php操作redis的常見用法詳解

    這篇文章主要為大家詳細(xì)介紹了php操作redis的常見用法的相關(guān)知識,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-11-11
  • PHP 將dataurl轉(zhuǎn)成圖片image方法總結(jié)

    PHP 將dataurl轉(zhuǎn)成圖片image方法總結(jié)

    這篇文章主要介紹了PHP 將dataurl轉(zhuǎn)成圖片image方法的相關(guān)資料,這里提供了兩種方法及實(shí)現(xiàn)方式,需要的朋友可以參考下
    2016-10-10
  • PHP封裝的數(shù)據(jù)庫模型Model類完整示例【基于PDO】

    PHP封裝的數(shù)據(jù)庫模型Model類完整示例【基于PDO】

    這篇文章主要介紹了PHP封裝的數(shù)據(jù)庫模型Model類,結(jié)合實(shí)例形式分析了php基于PDO針對mysql數(shù)據(jù)庫常見增刪改查、統(tǒng)計(jì)、判斷等相關(guān)操作封裝與使用技巧,需要的朋友可以參考下
    2019-03-03
  • PHP驗(yàn)證類的封裝與使用方法詳解

    PHP驗(yàn)證類的封裝與使用方法詳解

    這篇文章主要介紹了PHP驗(yàn)證類的封裝與使用方法,涉及php針對郵箱、手機(jī)號、字符串相關(guān)驗(yàn)證操作封裝與使用技巧,需要的朋友可以參考下
    2019-01-01

最新評論

获嘉县| 都江堰市| 华亭县| 奈曼旗| 衡东县| 大关县| 孟村| 博野县| 任丘市| 治多县| 福贡县| 常宁市| 柘荣县| 泰和县| 辽宁省| 克拉玛依市| 景德镇市| 珠海市| 五原县| 丁青县| 大悟县| 海宁市| 鄂温| 太和县| 武强县| 于都县| 汉沽区| 揭西县| 安远县| 兴义市| 法库县| 永安市| 仁化县| 惠水县| 张家川| 滁州市| 会同县| 巫山县| 通江县| 白玉县| 古蔺县|