ethanbeyer Posted May 22, 2018 Share Posted May 22, 2018 Not sure if this is possible - but I'd like to add something like this to cached pages via Template Cache: <!-- Page Cache Generated 2018-05-22 @ 12:45:44 UTC / Expires 2018-05-29 @ 12:45:44 --> I thought there might be a way to see if a cache file existed for the page in question, and if it did not, to include that comment in the render->cacheFile->save(). Does anyone know? Link to comment Share on other sites More sharing options...
ethanbeyer Posted May 22, 2018 Author Share Posted May 22, 2018 As a follow-up...has anyone ever built a site using delayed output with template caching? This is a new frontier for me and I don't know how to set it up. Link to comment Share on other sites More sharing options...
Robin S Posted May 23, 2018 Share Posted May 23, 2018 I haven't used template cache because I use ProCache instead, but wouldn't it simply be a matter of including the current date/time inside an HTML comment in your template files (or _main.php if using delayed output)? When a cached version is served you will see the time that was current when the markup was generated. Link to comment Share on other sites More sharing options...
ethanbeyer Posted May 23, 2018 Author Share Posted May 23, 2018 In theory, yes - but the largest problem with that approach is that the timestamp is always there. This is mostly for my OCD brain, but I essentially wanted a sanity check in the source that would quickly show that a page was or was not cached, and when. Link to comment Share on other sites More sharing options...
Robin S Posted May 24, 2018 Share Posted May 24, 2018 12 hours ago, ethanbeyer said: the largest problem with that approach is that the timestamp is always there If you only want to output the timestamp comment if the page has template cache enabled you could do a conditional like this: if($page->template->cache_time > 0) { // Output your timestamp comment } There are some other cache-related properties present in Template objects that you can explore with Tracy Debugger in case they are useful to your goal. bd($page->template); 1 Link to comment Share on other sites More sharing options...
ethanbeyer Posted May 24, 2018 Author Share Posted May 24, 2018 13 hours ago, Robin S said: If you only want to output the timestamp comment if the page has template cache enabled you could do a conditional like this: if($page->template->cache_time > 0) { // Output your timestamp comment } At the risk of sounding very pedantic, this condition would result in the timestamp for any page with template cache enabled, which is not what I'm looking for. I only want the timestamp to appear on cached versions of the page - so if I am logged in, and am served a page that doesn't give cached pages to logged-in users, I don't want the timestamp (or maybe I would have a different comment that said this page was generated now and is not cached, etc). On the other hand, if I was not logged in, and looked at the source for the same page and was served the Cached version, I'd expect to see the timestamp. Essentially, I am looking to inject the comment ONLY at the time of the creation of the cached page, not on normal render - so this makes me wonder if there's a hook I could grab before page render to determine whether or not the page render was being performed in order to create a CacheFile. Does this make sense? 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