Access expire information about a cached template

23 views
Skip to first unread message

Fran Dieguez

unread,
Nov 16, 2012, 2:48:50 PM11/16/12
to smarty-d...@googlegroups.com
Hi all,

I'm using Smarty in an application that uses Varnish as a reverse proxy
that handles all the request in front of a lot of application servers.

Varnish avoids hitting the applications server by caching the request.
If you want to control the cacheability of the requests you can do it
with the "Expire" http header sending it from the application.

I'm able to set this required header with
header('Expire: A DATE CALCULATED BY the Application');

Although, if I'm using smarty caching, those cached pages are "static"
until the cache expires. I want to get the expiration time that Smarty
knows and use it as the expire header to send it to Varnish.

So, Is there any chance of getting the expire time of the cache file by
using and Smarty function?

Cheers
--
Fran Dieguez

uwe.tews

unread,
Nov 17, 2012, 5:12:25 PM11/17/12
to smarty-d...@googlegroups.com
You can obtain the expiration time of the cache file as follow:

$tpl = $smarty->createTemplate('foo.tpl');
if ($tpl->cached->timestamp) {
   $expires = $tpl->cached->timestamp + $smarty->cache_lifetime;
} else {
  // cache file does not exists

Fran Dieguez

unread,
Nov 19, 2012, 5:19:34 AM11/19/12
to smarty-d...@googlegroups.com, uwe.tews
> --
> You received this message because you are subscribed to the Google
> Groups "Smarty Developers" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/smarty-developers/-/NcSsBH_0zA4J.
> To post to this group, send email to smarty-d...@googlegroups.com.
> To unsubscribe from this group, send email to
> smarty-develop...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/smarty-developers?hl=en.

Thanks for the quick reply.
Your snippet is working like a charm.

Cheers

--
Fran Dieguez

aurelien gerits

unread,
Nov 19, 2012, 6:25:42 AM11/19/12
to smarty-d...@googlegroups.com
This example can be added in the documentation?
Best regards

Créateur de Magix CMS
Créateur de Magix cjQuery
Administrateur de Magix Dev, une agence web proche du client




2012/11/19 Fran Dieguez <lis...@mabishu.com>
To post to this group, send email to smarty-developers@googlegroups.com.

To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/smarty-developers?hl=en.
Thanks for the quick reply.
Your snippet is working like a charm.


Cheers

--
Fran Dieguez

--
You received this message because you are subscribed to the Google Groups "Smarty Developers" group.
To post to this group, send email to smarty-developers@googlegroups.com.
To unsubscribe from this group, send email to smarty-developers+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages