Thursday, July 29, 2010

Re: generate cache by visiting protected links

>    ret_val = stats_top_callers_per_year(_request)
>    cache.set(reverse("stats_top_callers_per_year"), ret_val)


it's your code and I won't try talk you out of it :)

However, I don't see any reason why you couldn't call
"stats_top_caller_per_year" from an external script, unless you do
some magic related to request in that function. You're overriding the
user to be the one with pk=1 anyway, so you can do the same in a
script launched by cron the same way.

As long as you have a system-wide cache (ideally memcached backend),
nothing prevents you from doing that.

As for the cache key, it can be anything you want as long as it's
unique, less than the backend allows (I think it's 250 chars for
memcached, see the docs) and does not contain whitespaces (some cache
backends do allow those). A common idiom is an md5 of something that
uniquely identifies the cache object, but in your case you'd be free
to call it "stats_top_callers_per_year" or similar. No need to play
with reverse().

It's all just Python and Django does not really get much in a way
unless needed. So, no one tells you what the cache keys must look
like, and it's unlikely that you'd stumble upon cache keys Django uses



You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment