Yii Framework Forum: Page Cache dependency / dependencies - Yii Framework Forum

Jump to content

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

Page Cache dependency / dependencies Rate Topic: -----

#1 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 22 November 2010 - 02:57 PM

Hi,

I call the cache in filters() in my Controller

public function filters()
{
    return array(
        array(
            'COutputCache',
            'duration'=>3600,
            'varyByParam'=>array('languages', 'value'),
        ),
    );
}


The site loads the content with the parameter language and value.
The Cache is working well, but I need the Id from the cached side. The site is static and can stay a long time in cached version until i make an update of the content.
Then I need the id from the site to delete the old site from the cache! But from where I get the id??

My Workflow is as follow:
1) Write a new dynamic site and save the data in the database
2) When the user calls the content, the site is cached in APC
3) When I update the content, I need the id from the old cached site to delete it.
4) Then I need a method to call the cache and get an cached site.

thank you for your help
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#2 User is offline   derelict 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 18-November 09
  • Location:Ukraine

Posted 22 November 2010 - 03:18 PM

Look at method getCacheKey of COutputCache class and you will identify how this id is generated.
0

#3 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 22 November 2010 - 04:13 PM

Thank you for your answer.
But how do I use getCacheKey and how can I start to cache the updated data's?
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#4 User is offline   derelict 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 18-November 09
  • Location:Ukraine

Posted 22 November 2010 - 04:34 PM

CacheKey is used to save and get data from cache. But I was not right in previous answer, the better way is using cache dependency. You may add field to your database table where you will store the time of last update and create dependency which uses this field. In this case the cache will be refreshed when the value of this field changes.
0

#5 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 22 November 2010 - 04:53 PM

View Postderelict, on 22 November 2010 - 04:34 PM, said:

CacheKey is used to save and get data from cache. But I was not right in previous answer, the better way is using cache dependency. You may add field to your database table where you will store the time of last update and create dependency which uses this field. In this case the cache will be refreshed when the value of this field changes.

That is a very good idea.
Could you make an small tutorial for this?

I don't know how to tell
public function filters()
{
    return array(
        array(
            'COutputCache',
            'duration'=>3600,
            'varyByParam'=>array('languages', 'value'),
        ),
    );
}

that it loads the content from the database?!
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#6 User is offline   derelict 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 18-November 09
  • Location:Ukraine

Posted 22 November 2010 - 05:07 PM

According to documentation it should be like this
public function filters()
{
	return array(
		array(
			'COutputCache',
			'duration' => 3600,
			'varyByParam' => array('languages', 'value'),
			'dependency' => array(
 				'class' => 'CDbCacheDependency',
 				'sql' => 'SELECT MAX(lastModified) FROM tableName',
			),
		),
	);
}

You may read this section to find out other cache dependencies.
0

#7 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 22 November 2010 - 05:10 PM

View Postderelict, on 22 November 2010 - 05:07 PM, said:

According to documentation it should be like this
public function filters()
{
	return array(
		array(
			'COutputCache',
			'duration' => 3600,
			'varyByParam' => array('languages', 'value'),
			'dependency' => array(
 				'class' => 'CDbCacheDependency',
 				'sql' => 'SELECT MAX(lastModified) FROM tableName',
			),
		),
	);
}

You may read this section to find out other cache dependencies.


thank you. Yes I readed the section but it is writen very poor.
What coloums do I need for my table?

id
lastModified
xxx???
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#8 User is offline   derelict 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 18-November 09
  • Location:Ukraine

Posted 22 November 2010 - 05:13 PM

In this example the column is lastModified.
0

#9 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 22 November 2010 - 05:15 PM

but I need a coloumn for the cache id or for the varyByParam' => array('languages', 'value'), ????
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#10 User is offline   derelict 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 18-November 09
  • Location:Ukraine

Posted 22 November 2010 - 05:20 PM

No. varyByParam is reffered to request's GET params. What data do you store in database now?
0

#11 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 22 November 2010 - 05:25 PM

the dynamic content is loaded from the table "stores".

stores
id
language
value

'dependency' => array(
   'class' => 'CDbCacheDependency',
   'sql' => 'SELECT MAX(lastModified) FROM tableName',


Now I understand, I have to alter the tabel stores and add a new coloum lastModified.

Can I start the Cache for every Id?

I'm only a little bit frustrated that I can't calculate the CacheKey.
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#12 User is offline   derelict 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 18-November 09
  • Location:Ukraine

Posted 22 November 2010 - 05:37 PM

COutputCache store in cache whole page's content and that's why it can not be bound to the id of database table, because controller's action is not bound to any model directly. You may store in cache not whole page but only the data you get from database.
0

#13 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 23 November 2010 - 01:04 PM

This solution is a little bit slow.
I think the Caching-System from yii have to improve!
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#14 User is offline   mocapapa 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 428
  • Joined: 04-January 09
  • Location:Tokyo, JAPAN

Posted 27 July 2011 - 11:22 PM

View Postyii, on 23 November 2010 - 01:04 PM, said:

This solution is a little bit slow.
I think the Caching-System from yii have to improve!


May be you must learn more. For example, CGlobalStateCacheDependency works fine for me. Thanks to this page cache scheme, my slow pages got x200 faster.

When you create/update/delete the new record, you should alter the global state using afterSave() or afterDelete() in your model.
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