Does cache timeout need to be set in two places?

2009-03-22 Thread rihad

>From Django Book http://www.djangobook.com/en/2.0/chapter15/ :

> CACHE_BACKEND = "locmem:///?timeout=30&max_entries=400"

but, a bit later:

> Then, add the following required settings to your Django settings file:
>* CACHE_MIDDLEWARE_SECONDS — The number of seconds each page should be 
> cached.


Why have two seemingly identical settings? Do I have to make sure
they're equal? What if they aren't? Or is the timeout= the cached
object lifetime per se, but CACHE_MIDDLEWARE_SECONDS is what is
actually told to web caches? Sorry I couldn't grasp the idea after
rereading The Book.


Another relevant q'n: can I configure the cache to expire at
appropriate time intervals, without coding the logic? Say, there's an
external event happening every 15 minutes that updates the original
data Django processes; can Django be configured to give web clients
the correct cache TTL? Example: the resource is regenerated externally
at 11:00:00. At 11:00:01 a client accesses it and it should be given
cache timeout up until 11:15:00, that is, 899 seconds. Client
accessing at 11:00:02 should be given timeout 898 seconds, and so on.
Then at 11:15:00 the resource is regenerated again and it comes full
circle until 11:30:00 this time, and so on.

Thanks for any tips.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Does cache timeout need to be set in two places?

2009-03-22 Thread Malcolm Tredinnick

On Sun, 2009-03-22 at 00:17 -0700, rihad wrote:
> From Django Book http://www.djangobook.com/en/2.0/chapter15/ :
> 
> > CACHE_BACKEND = "locmem:///?timeout=30&max_entries=400"
> 
> but, a bit later:
> 
> > Then, add the following required settings to your Django settings file:
> >* CACHE_MIDDLEWARE_SECONDS — The number of seconds each page should be 
> > cached.
> 
> 
> Why have two seemingly identical settings? Do I have to make sure
> they're equal? What if they aren't? Or is the timeout= the cached
> object lifetime per se, but CACHE_MIDDLEWARE_SECONDS is what is
> actually told to web caches? 

The CACHE_MIDDLEWARE_SECONDS is used to compute the HTTP cache header
times. The caching middleware that it refers to (in the name) is for
short-circuiting computation using HTTP-level caching headers. It uses
Django's low-level cache, but is not the same thing.

> Sorry I couldn't grasp the idea after
> rereading The Book.
> 
> 
> Another relevant q'n: can I configure the cache to expire at
> appropriate time intervals, without coding the logic? Say, there's an
> external event happening every 15 minutes that updates the original
> data Django processes; can Django be configured to give web clients
> the correct cache TTL? Example: the resource is regenerated externally
> at 11:00:00. At 11:00:01 a client accesses it and it should be given
> cache timeout up until 11:15:00, that is, 899 seconds. Client
> accessing at 11:00:02 should be given timeout 898 seconds, and so on.
> Then at 11:15:00 the resource is regenerated again and it comes full
> circle until 11:30:00 this time, and so on.

No, it doesn't work this way. If you want per-object cache times to be
set specifically, you should write your own view decorator or utility
function to do so.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---