1
votes
php cache zend framework - Stack Overflow
Asked
Viewed 1k times
1

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 zendfrmawork

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

Only zend framwork.

1
  • do/can you use APC/eAccelerator PHP extension if not reading entire input.txt with file_get_contents on each request would work just fine
    – bas
    Nov 12 2010 at 20:05
1

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

    1

    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;
    }
    
      0

      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.

        Your Answer

        By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

        Not the answer you're looking for? Browse other questions tagged or ask your own question.

         
        3
        do/can you use APC/eAccelerator PHP extension if not reading entire input.txt with file_get_contents on each request would work just fine - bas

        3 Answers

        1
        votes

        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

        1
        votes

        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;
        }
        
        0
        votes

        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.