Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty caching

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
KakkArlak
Smarty Rookie


Joined: 25 Nov 2009
Posts: 8

PostPosted: Tue Dec 07, 2010 8:27 pm    Post subject: Smarty caching Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 07, 2010 8:30 pm    Post subject: Reply with quote

Set a cache_id. See the docs on multiple page caches.

http://www.smarty.net/docs/en/caching.multiple.caches.tpl
Back to top
View user's profile Send private message Visit poster's website
KakkArlak
Smarty Rookie


Joined: 25 Nov 2009
Posts: 8

PostPosted: Tue Dec 07, 2010 8:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 07, 2010 8:42 pm    Post subject: Reply with quote

I see what you want now. One way to do it:

Code:
{myPluginFoo}


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
View user's profile Send private message Visit poster's website
KakkArlak
Smarty Rookie


Joined: 25 Nov 2009
Posts: 8

PostPosted: Tue Dec 07, 2010 8:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 07, 2010 8:48 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
KakkArlak
Smarty Rookie


Joined: 25 Nov 2009
Posts: 8

PostPosted: Tue Dec 07, 2010 8:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 07, 2010 9:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
KakkArlak
Smarty Rookie


Joined: 25 Nov 2009
Posts: 8

PostPosted: Tue Dec 07, 2010 10:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
wern0561
Smarty Rookie


Joined: 05 Jan 2009
Posts: 13

PostPosted: Mon Feb 28, 2011 10:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
padege
Smarty n00b


Joined: 24 Mar 2011
Posts: 1

PostPosted: Thu Mar 24, 2011 2:38 pm    Post subject: Reply with quote

Thank you
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP