So would I put that class in my settings.py? Where would I put that
class to make sure that the data is frequently retrieved from local
memory?

On Feb 8, 4:47 pm, akaariai <akaar...@gmail.com> wrote:
> On Feb 9, 12:14 am, bfrederi <brfrederi...@gmail.com> wrote:
>
> > I have some data that I retrieve using urllib and then cache on a
> > different server that I frequently use through my site. Since it gets
> > used so frequently, I was wondering why it might be a good/bad idea to
> > make the urllib request in the settings.py. It's data that gets
> > changed infrequently, but should update every once in a while, but I'd
> > prefer that it stayed in local memory as much as possible, since it
> > gets used so much. Any advice on how to make a dynamic global variable
> > like that is much appreciated.
>
> Don't do that in settings.py. Use Django's caching framework. Or
> something like:
> class MyUrlLoader(object):
>     cache = {} # map of url -> (timeout cutpoint, data)
>     def get_data(url):
>            val = self.cache.get(url)
>            if val is None or datetime.now() > val[0]:
>                 val = (datetime.now() + timedelta(seconds=60),
> loaded_data)
>                 self.cache[url]  = val
>            return val[1]
>
> No idea if the above actually works, but the idea should work. But you
> really are duplicating what the cache framework does, so first try
> that.
>
>  - Anssi

-- 
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.

Reply via email to