开发者

php cache zend framework

server side is PHP + zend framework.

problem:

i have huge of data appox 5000 records and no of columns are 5 in input.txt file. i like to read all data into memory only once and send some data to the every browser request. but if i update that input.txt file then updated data must be auto synchronized to that memory location.

so i need to solve that problem by using memory caching technique.but caching technique has expire time.but if input.txt is updated before cache expire then i need to auto synchronize to that memory location.

now i am using zend framework 1.10.is it possible in zend framework. can anybody give me some line of code of zend开发者_如何学编程frmawork

i have no option to use memchached server(distributed).

Only zend framwork.


It is possible to cache something like that using zend framework. Check Zend documentation online - its not complete but can give you a head start: http://framework.zend.com/manual/en/zend.cache.introduction.html


Use lazy loading like this (1h cache is usually OK).

function getData() {
    $cache = ...; //get your memory cache here
    $cacheId = 'MyCacheId'; //cache id for your data
    $loadTimeCacheId = 'dataLoadCacheId'; //cache id for data load timestamp
    $cacheLength = 3600; //seconds

    $data = $cache->load($cacheId);
    $loadTime = (int) $cache->load($loadTimeCacheId);

    if (!$data || filemtime('/path/to/your/file') > $loadTime) {
        $data = ...; //real loading here

        $cache->save($data, $cacheId, array(/*no tags*/), $cacheLength); //save data to cache
        $cache->save(time(), $loadTimeCacheId, array(/*no tags*/), $cacheLength); //save load timestamp
    }

    return $data;
}


Best option is to use Zend_Cache_Frontend_File pointed to your file and Zend_Cache_Backend_Memcached. There is virtually no other option how to store anything in memory than Memcache or APC. It cannot be done without external extension IMO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜