View previous topic :: View next topic |
Author |
Message |
KakkArlak Smarty Rookie
Joined: 25 Nov 2009 Posts: 8
|
Posted: Tue Dec 07, 2010 8:27 pm Post subject: Smarty caching |
|
|
Hi,
So I've got caching set up for all my pages, etc etc.
I've got a custom plugin that display's content from a databases on every page. How can I cache those plugins individually ? Instead of, when one of those gets updated, clearing that whole page's cache.
In the CMS, when on of those "content" items gets updated, I want to clear the cache for only THAT ONE.
How can I do that?
Thanks! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
KakkArlak Smarty Rookie
Joined: 25 Nov 2009 Posts: 8
|
Posted: Tue Dec 07, 2010 8:35 pm Post subject: |
|
|
Yes, I am doing that. I'm not sure I understand?
I have cache id's on everything, and I group my templates.. but these "plugins" showing content is seperate. Probably 5-6 on each page. how would I set cache id's for them seperately? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Dec 07, 2010 8:42 pm Post subject: |
|
|
I see what you want now. One way to do it:
Be sure you register your plugin as non-cached. Then the contents from your plugin will always be dynamic. If you want that content cached between updates, you would handle that from within your plugin itself. |
|
Back to top |
|
KakkArlak Smarty Rookie
Joined: 25 Nov 2009 Posts: 8
|
Posted: Tue Dec 07, 2010 8:44 pm Post subject: |
|
|
Yes, it does work like that.
It's
{page_contents ...some parameters...}
but, and I read about setting it as "not cache" and whatever on registering the plugin ... but what I'm confused about is, I'm not registering the plugin? I just added it in a "custom plugins" folder and added that in an array as the "plugins_dir" ? Or is that not the right way to do it? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Dec 07, 2010 8:48 pm Post subject: |
|
|
You would have to use registerPlugin() to make the plugin uncached. a work around would be in the template:
Code: | {nocache}{myPluginFoo}{/nocache} |
|
|
Back to top |
|
KakkArlak Smarty Rookie
Joined: 25 Nov 2009 Posts: 8
|
Posted: Tue Dec 07, 2010 8:58 pm Post subject: |
|
|
Yes, that's the other question I had.
If I use nocache tags around the plugins, how would I then cache the plugin inside? ( if even possible ) |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Dec 07, 2010 9:04 pm Post subject: |
|
|
You would cache it using your own caching mechanism inside the plugin itself. Just keep a copy of the cache in a flat file, memcache, or whatever works best. There may be some other solutions floating around, you might search the forums (ClipCache comes to mind). We are investigating how to make parts of pages cache easier. |
|
Back to top |
|
KakkArlak Smarty Rookie
Joined: 25 Nov 2009 Posts: 8
|
Posted: Tue Dec 07, 2010 10:16 pm Post subject: |
|
|
ah okay, I would've wanted to keep all my caching in smarty. But if I can't do that then I'll just have to make another plan. |
|
Back to top |
|
wern0561 Smarty Rookie
Joined: 05 Jan 2009 Posts: 13
|
Posted: Mon Feb 28, 2011 10:42 pm Post subject: |
|
|
If you are using mysql as your database you should look into the mysql query cache. http://dev.mysql.com/doc/refman/5.1/en/query-cache.html Basically when you run a query it saves the result of that exact query. When you run it again as long as your table hasn't changed it sends back the cached result, but whenever a change is made to the table the cache is deleted. While it might not be as powerful as something like memcache it does exactly what you are describing. It won't save you much if you are doing a lot of processing with the results but if you are looking to just cache an expensive query this might be a good alternative. You just have to make sure you have it enabled and your queries are written to take advantage of it. It might even be working already. This is most effective for tables that don't change a lot. |
|
Back to top |
|
padege Smarty n00b
Joined: 24 Mar 2011 Posts: 1
|
Posted: Thu Mar 24, 2011 2:38 pm Post subject: |
|
|
Thank you |
|
Back to top |
|
|