Enonic version: 7.2.0
I am investigating a possibility to generate a cache site wide for some content. It seems like cache works for specific page only, meaning it generates different cache, even if it has the same key for each page. Please, correct me if I’m wrong.
For example, we have a set of data, which is calculated ~1s, which appears on every page of our website and we want it cached. Is it possible to cache it once for the whole website and pull it by the key?
The original idea is to generate a cache once a day with a cronjob app (https://market.enonic.com/vendors/enonic/cronjob) and when the page is loaded, just use the generated cache.
Wouldn’t this be to simply create some service, add the cache-lib and a cache getter there, call this getter from any controller you need the content in? Or even simpler, add the cache lib to the controller for some common/default page template?
We use this i.e. in our search service. Not for use on all pages, but the principle is the same. We cache (among other things) the very expensive generating of image urls at the top of our file here: https://github.com/oslokommune/labs.oslo.kommune.no/blob/master/src/main/resources/services/search/search.js
I just love the cache lib in enonic xp. Pretty much the simplest cache service I’ve ever played with.
Thanks for a suggestion.
However the issue that I see here is that cache is generated specifically for each page. For example, if we have “/home”, “/blog” and “/about”( all of them are different templates ) and all of these pages have cache with a key “banner”, each of these pages will have it’s own cache “banner” and it will not be pulled from the same source, meaning cache is generated three times and is stored three times too.
I have also made a quick test and if pages have the same template, the cache with the same key is used. For example, if there is an article template, all of the articles will share the cache by key.
If caching is working the way I described, it makes service and/or cronjob that generates cache useless, since it will be generated for a current controller.
As mentioned before, I might mistake, but currently it looks to me to work this way.
I have implemented a library to create and manage global caches by storing the cache object created with cacheLib on “app” global variable. But the project is using enonic 6.15. I don’t know if it would work on XP7.
If you could share the lib, that would be great. I could try upgrading it to XP 7 or see if it works out of the box.
At beginning it was intended for caching all contents of custom content type from database. Then we use it along with main.js publish/delete events, and with a custom contentLib wrapper that gets from cache instead of database. I hope you can make a better use than us
Some input here, caching raw content should not provide any signific performance improvement as this is already optimized in XP. Caching processed results, or results from complex queries willl be more useful.
For my project with old source code and bad initial design, this also badly designed lib (), as incredible as it may seem, reduced some page loading time from 6~7 seconds to 300~600 milliseconds, in the best cases.
Wow! This is what I was looking for. Creating cache in app object is a solution, which I have not thought of FYI, it works out of the box with XP7.
Thank you very much for sharing this!