maheshs4677 Posted February 10, 2010 Share Posted February 10, 2010 Hi All, I've just started using Zend Cache. I am trying to store an entire HTML in the cache, however it is not storing anything. Here is my code, any help much appreciated. <?php include_once "Zend/Cache.php"; include_once 'f1.php'; $frontendOptions = array('lifetime' => 6,'automatic_serialization' => true); $backendOptions = array('cache_dir' => '/tmp/'); $cache = Zend_Cache::factory('Output', 'File', $frontendOptions, $backendOptions); $pageid = 'MYTEST'; ZendCacheData($pageid); /******************* ZEND CACHE FUNCTIONS *****************************/ function ZendCacheData( $pageid ) { global $cache; if (!($cache->test($pageid))) { // ShowMainMarkets1() Function returns an HTML paqe $returnData = ShowMainMarkets1(); $cache->save( $returnData, $pageid ); } else { $returnData = $cache->load($pageid); $returnData = $returnData; } echo $returnData; } ?> Link to comment https://forums.phpfreaks.com/topic/191601-zend-cache-caching-html/ Share on other sites More sharing options...
thehippy Posted February 10, 2010 Share Posted February 10, 2010 Instead of 'Output' use 'Core', you've coded a core usage, not an output buffered one. Link to comment https://forums.phpfreaks.com/topic/191601-zend-cache-caching-html/#findComment-1010008 Share on other sites More sharing options...
maheshs4677 Posted February 10, 2010 Author Share Posted February 10, 2010 Thanks very much. I solved it by still using ob_start() and ob_get_contents() as the function I called was outputting HTML and the $returnData was always empty due to that. The code change is as follows. ob_start(); ShowMainMarkets1(); $dataStr = "'" . ob_get_contents() . "'"; $cache->save( $dataStr, $pageid ); ob_clean(); Hope this is appropriate usage. If you think, Core is better suited for my needs, please let me know and I will re-code and see what happens. Thanks again! Link to comment https://forums.phpfreaks.com/topic/191601-zend-cache-caching-html/#findComment-1010012 Share on other sites More sharing options...
thehippy Posted February 10, 2010 Share Posted February 10, 2010 Output buffering with Zend_Cache uses the functions $cache->start(key) and $cache->end(), not the $cache->load(key), $cache->save() functions. Example usage here. Link to comment https://forums.phpfreaks.com/topic/191601-zend-cache-caching-html/#findComment-1010356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.