Reputation: 6121
Let's say I have model called Event. And Events are constantly being created and updated.
I have a two clients now that are interested in some subsets of Events. They maybe interested in two different subsets or in just one subset.
One client is in python, one is in browser and there could be more in the future.
So I was thinking about creating some code that would poll DB and then send id's of interesting Events to clients and clients would retrieve them from DB in some way (maybe through http request, maybe through query). Another option I see is send serialized Events instead of their id's.
And we are close now to my question. Maybe I should create another table for this 'interesting' events for every client and they would poll it? But I don't know how to do that with django (I can do that with raw sql of course, but I don't know what is the 'django way' of doing that).
So what do you think of that idea?
Upvotes: 0
Views: 56
Reputation: 793
There is a database cache backend in the core django, see https://docs.djangoproject.com/en/dev/topics/cache/#database-caching for more information.
Basicaly you have to put this in the settings
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'my_cache_table',
}
}
Then you can cache stuffs like that
from django.core.cache import cache
CACHE_KEY = 'events'
events = cache.get(CACHE_KEY, None)
if events is None:
events = get_events()
cache.set(CACHE_KEY, events, 3600) # expires in 1 hour
return events
Howerver I dont see the point of caching the query returning the subset of events, except if this query is very complex and cpu/time consumming.
Upvotes: 1