Adam Kiss Posted July 31, 2012 Share Posted July 31, 2012 Hey Ryan, could you write a little on how to start with MarkupCache please? How it is used, what are the situations you want to use it and such; I for instance would like this to use with textformatter: I am running quite heavy processing on parts of page content, and would like to cache the result, so I don't have to rerun it again, but I am not sure, where goes what with MarkupCache. Thank you 1 Link to comment Share on other sites More sharing options...
Soma Posted July 31, 2012 Share Posted July 31, 2012 does that help ? 2 Link to comment Share on other sites More sharing options...
ryan Posted July 31, 2012 Share Posted July 31, 2012 Adam did that page Soma linked to solve your question? There isn't much to the MarkupCache module: just $cache->get('your-unique-name', $num_seconds); and $cache->save($your_markup). Let me know if you have any other questions on how to use it. Link to comment Share on other sites More sharing options...
Adam Kiss Posted July 31, 2012 Author Share Posted July 31, 2012 Yeah, it did... partly. Mainly: Is the cache tied to page, or do I have to supply the differentiation Does it work only for string (HTML), or can I supply also objects (and it'll take care of serialisation?) Is the cache autodeleted? Meaning: do I only check for presence (if I want to save CPU time) How do I invalidate cache (upon Page save, for instance) Is this available for modules? Thanks Link to comment Share on other sites More sharing options...
ryan Posted July 31, 2012 Share Posted July 31, 2012 The cache is not connected with any page. The only thing that identifies it is the name that you provide for it in the $cache->get('name-of-cache', $seconds); call. It only works for strings. It's intended to cache markup (HTML) per the name MarkupCache. But I don't see any reason why you couldn't serialize an object to a string and cache it with MarkupCache, but you'd have to do the serialization yourself. When the cache is cleared is determined by the duration you specify (in seconds) as the second param to the $cache->get() call. You can also configure it to clear on every page save in the module settings (Admin > Modules > Markup > Cache). There is also a manual cache clear toggle there as well. Modules, templates and core in ProcessWire all use the same stuff, so there's no limits there. You could certainly use it from a module if you wanted to. But get() your cache only when you intend to output it or save it right there, because cache calls can't be nested. 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted July 31, 2012 Author Share Posted July 31, 2012 Thanks Ryan Is there any API call to purge (/delete/invalidate) cache? If I'll use this as a part of module, I can't rely on site administrator setting up things properly Link to comment Share on other sites More sharing options...
Pete Posted July 31, 2012 Share Posted July 31, 2012 I think you could just invalidate it by setting the expiry to zero: $cache->get('your-unique-name', 0); but I'm not sure whether that would remove any cache files if that's what you're looking for? Link to comment Share on other sites More sharing options...
Adam Kiss Posted July 31, 2012 Author Share Posted July 31, 2012 I would like the invalidation to remove old files as well, yes Link to comment Share on other sites More sharing options...
ryan Posted July 31, 2012 Share Posted July 31, 2012 You can do this: $cache->removeAll(); If you want to remove an individual cache, you'd want to do what Pete suggested. Link to comment Share on other sites More sharing options...
Jeroen_1980 Posted February 23, 2013 Share Posted February 23, 2013 I know this is an old thread, but it was one of the first results when I searched for 'ProcessWire Object Cache'. I wanted to store a lot of objects in the cache, so I just converted the MarkupCache module to an ObjectCache module. Nothing fancy; it just adds (un)serialize to the get/save methods. But that alone saves me quite a but of time in this project and results in cleaner (less logic) templates. The code is available for free (and at your own risk ) at https://gist.github.com/jkenters/5019089 5 Link to comment Share on other sites More sharing options...
ryan Posted February 25, 2013 Share Posted February 25, 2013 Very cool Jeroen. Can you tell us more about how you are using it? Would love to hear more about the use cases and benefits. Maybe it's something that belongs as an option in MarkupCache. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted February 25, 2013 Share Posted February 25, 2013 @jeroen, You've a familiar name. Think I recognize your name from some dutch MODX meeting or something. Good to see you here. Link to comment Share on other sites More sharing options...
Jeroen_1980 Posted March 3, 2013 Share Posted March 3, 2013 Very cool Jeroen. Can you tell us more about how you are using it? Would love to hear more about the use cases and benefits. Maybe it's something that belongs as an option in MarkupCache. The markup depends on a few factors (page the user is on, current time, etc) so caching the data as a PHP array saves quite a bit of database lookups and even some processing (like price calculations etc), while still allowing me to do the needed markup changes per request. Regular markup cache would not work in this case or would require many markup caches per page. @jeroen, You've a familiar name. Think I recognize your name from some dutch MODX meeting or something. Good to see you here. Still using MODX (I'm even a "MODX Ambassador") so maybe we indeed met at a meetup or MODXpo in Utrecht last year. Having both MODX and ProcessWire really makes web development fun. Both are great systems to work with. 1 Link to comment Share on other sites More sharing options...
thomas Posted March 3, 2013 Share Posted March 3, 2013 I use MarkupCache to cache JSON data all the time so I'll definitely take a look at your code, Jeroen. Thanks Link to comment Share on other sites More sharing options...
ryan Posted March 4, 2013 Share Posted March 4, 2013 The markup depends on a few factors (page the user is on, current time, etc) so caching the data as a PHP array saves quite a bit of database lookups and even some processing (like price calculations etc), while still allowing me to do the needed markup changes per request. Regular markup cache would not work in this case or would require many markup caches per page. Sounds good, makes sense to me. I will put in a todo in MarkupCache to support the serialize/unserialize where appropriate. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now