0

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?

6
  • Since you need Events but in different terms, then you don't need an additional table, you just need the necessary filtering requirements. Your question though is not clear in terms of the help you are asking regarding Django, if you are trying to create something in Django and you know nothing of it, then your only help is clearly to read the detailed and rich (in terms of information) documentation: docs.djangoproject.com/en/1.6 Commented Aug 6, 2014 at 10:33
  • Of course I can filter Events with query. But if I have two clients. And they can be interested in one subset of events or not. If former than I think executing the same query twice is inefficient. Also I don't want to duplicate code of a query. Commented Aug 6, 2014 at 10:38
  • I'm using django for some time now. I can create another model of course like InterestingEvent that would have Event. That would create another table with Interesting events with link to actual Event. Commented Aug 6, 2014 at 10:41
  • You don't need to duplicate anything, you can create a Model Manager with 2 different methods, one for each client, if you need different subsets in the future extend the manager, 2 different requests / filters are not the same query, they have different terms and handled differently so obviously we are not talking about the same query twice. Commented Aug 6, 2014 at 10:45
  • What it they interested in one subset? Then there would be two exactly the same queries right? Commented Aug 6, 2014 at 10:49

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that is interesting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.