Yii Framework Forum: Curlmanager Addcacherules - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Curlmanager Addcacherules Rate Topic: -----

#1 User is offline   KJL Jon 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-September 12

Posted 21 November 2012 - 04:15 PM

I am creating an application where there are UserGroups and Users.

The problem is that every UserGroup has a different alias that they like in the Url (but the application is all the same).

Example:
One might call Enemies while another Baddies.

I am currently doing this:
Yii::createWebApplication($config);
Yii::app()->urlManager->addRules(UserGroup::getUrls());
Yii::app()->run();


and I don't set any rules in the $config.

I would like to take advantage of the Url Caching, but using addRules only addeds it to the $_rules[] and doesn't cache it.

At first, I was thinking to change the private to protected and extending the class and overriding processRules(). But I wanted to find a more "permanent" solution for people to use in the future (without adding another request to make private variables protected).

doing this would require additional cache parameters.

I would like to see something like:
private $_cacheKey=self::CACHE_KEY;


Then here is the function I would for addCacheRules:
public function addCacheRules($rules,$cache='',$append=true)
{
	$this->_cacheKey.='.'.$cache;
	
	if ($append)
	{
		$this->rules = array_merge($rules,$this->rules);
	}
	else
	{
		$this->rules = array_merge($this->rules,$rules);
	}
}


and then processRules would look as follow (only changed self::CACHE_KEY -> $this->_cacheKey ):
protected function processRules()
{
	if(empty($this->rules) || $this->getUrlFormat()===self::GET_FORMAT)
		return;
	if($this->cacheID!==false && ($cache=Yii::app()->getComponent($this->cacheID))!==null)
	{
		$hash=md5(serialize($this->rules));
		if(($data=$cache->get($this->_cacheKey))!==false && isset($data[1]) && $data[1]===$hash)
		{
			$this->_rules=$data[0];
			return;
		}
	}
	foreach($this->rules as $pattern=>$route)
		$this->_rules[]=$this->createUrlRule($route,$pattern);
	if(isset($cache))
		$cache->set($this->_cacheKey,array($this->_rules,$hash));
}


maybe there is a better way that I am missing?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users