Return to Snippet

Revision: 17313
at August 31, 2009 21:51 by iloveitaly


Initial Code
protected function checkCacheData($prefix = FALSE, $vars = FALSE) {
	if($vars == FALSE) {
		$vars = input::instance()->get();
	}
	
	if($prefix === FALSE) {
		$prefix = Router::$method;
	}
	
	if(empty($vars)) {
		$cacheKey = 'empty';
	} else {
		asort($vars);
		$queryString = http_build_query($vars);
		$cacheKey = md5($queryString);
	}
	
	if($cachedData = $this->cache->get(Router::$controller'.'.$prefix.$cacheKey)) {
		return $cachedData;
	} else {
		return FALSE;
	}
}

protected function setCacheData($data, $prefix = FALSE, $vars = FALSE) {
	if($vars == FALSE) {
		$vars = input::instance()->get();
	}
	
	if($prefix === FALSE) {
		$prefix = Router::$method;
	}
	
	if(empty($vars)) {
		$cacheKey = 'empty';
	} else {
		asort($vars);
		$cacheKey = md5(http_build_query($vars));
	}
	
	$this->cache->set(Router::$controller.'.'.$prefix.$cacheKey, $data);
}

Initial URL

                                

Initial Description
Useful for controllers. Put this in your base class for easy caching on variable (GET, POST) dependent pages

Initial Title
Easy Kohana Cache For Variable Dependent Pages

Initial Tags
cache

Initial Language
PHP