13

i have a Model in my app, that is used so much in my application, some views made something like 100 queries in that Table, I already have a tons of optimisations to make a better use of this Model, but the great part of that amount is caused by the Django init method of other classes, for personal reasons... So actual i just put a global variable to store all the objects of that Model in there, so when i create or delete a one object from that Model I just reload that List... but i dont want to use cache machines like Memcached or Redis... i just want to store that QuerySet result in the Memory... And i want to still use the Managers in this cached Queryset.

Thanks in advance and sorry for my bad english.

Luan Fonseca
  • 1,467
  • 1
  • 13
  • 22

2 Answers2

14

You can use Django's provided caching.

This answer to a very similar question gets you on the right track.

Community
  • 1
  • 1
Joseph
  • 12,678
  • 19
  • 76
  • 115
1

I would suggest implementing a custom model manager and a query set. A django cache backend doesn't have to be memcached or redis it can be localmemory also, although I would advise you to stand up a real cache backend. We mostly have been using https://github.com/jmoiron/johnny-cache for this purpose but found it is not compatible with django > 1.6 so we are switching over to https://github.com/vijaykatam/django-cache-manager

Vijay Katam
  • 1,291
  • 1
  • 9
  • 8