django-cache

Why is Django returning stale cache data?

陌路散爱 提交于 2019-12-01 16:52:17
I have two Django models as shown below, MyModel1 & MyModel2 : class MyModel1(CachingMixin, MPTTModel): name = models.CharField(null=False, blank=False, max_length=255) objects = CachingManager() def __str__(self): return "; ".join(["ID: %s" % self.pk, "name: %s" % self.name, ] ) class MyModel2(CachingMixin, models.Model): name = models.CharField(null=False, blank=False, max_length=255) model1 = models.ManyToManyField(MyModel1, related_name="MyModel2_MyModel1") objects = CachingManager() def __str__(self): return "; ".join(["ID: %s" % self.pk, "name: %s" % self.name, ] ) MyModel2 has a

Why is Django returning stale cache data?

爱⌒轻易说出口 提交于 2019-12-01 15:00:49
问题 I have two Django models as shown below, MyModel1 & MyModel2 : class MyModel1(CachingMixin, MPTTModel): name = models.CharField(null=False, blank=False, max_length=255) objects = CachingManager() def __str__(self): return "; ".join(["ID: %s" % self.pk, "name: %s" % self.name, ] ) class MyModel2(CachingMixin, models.Model): name = models.CharField(null=False, blank=False, max_length=255) model1 = models.ManyToManyField(MyModel1, related_name="MyModel2_MyModel1") objects = CachingManager() def

django querysets + memcached: best practices

浪子不回头ぞ 提交于 2019-11-30 06:42:17
Trying to understand what happens during a django low-level cache.set() Particularly, details about what part of the queryset gets stored in memcached. First, am I interpreting the django docs correctly? a queryset (python object) has/maintains its own cache access to the database is lazy; even if the queryset.count is 1000, if I do an object.get for 1 record, then the dbase will only be accessed once, for that 1 record. when accessing a django view via apache prefork MPM, everytime that a particular daemon instance X ends up invoking a particular view that includes something like "tournres

How do you know if memcached is doing anything?

扶醉桌前 提交于 2019-11-28 16:02:58
I'm testing out using memcached to cache django views. How can I tell if memcached is actually caching anything from the Linux command line? I know this question is old, but here is another useful approach for testing memcached with django: As @Jacob mentioned, you can start memcached in very verbose mode (not as a daemon): memcached -vv To test your django cache config, you can use the low-level cache api. First, start up the python interpreter and load your django project settings: python manage.py shell From the shell, you can use the low-level cache api to test your memcache server: from

Per-request cache in Django?

淺唱寂寞╮ 提交于 2019-11-28 06:28:37
I would like to implement a decorator that provides per-request caching to any method, not just views. Here is an example use case. I have a custom tag that determines if a record in a long list of records is a "favorite". In order to check if an item is a favorite, you have to query the database. Ideally, you would perform one query to get all the favorites, and then just check that cached list against each record. One solution is to get all the favorites in the view, and then pass that set into the template, and then into each tag call. Alternatively, the tag itself could perform the query

How do you know if memcached is doing anything?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 09:28:13
问题 I'm testing out using memcached to cache django views. How can I tell if memcached is actually caching anything from the Linux command line? 回答1: I know this question is old, but here is another useful approach for testing memcached with django: As @Jacob mentioned, you can start memcached in very verbose mode (not as a daemon): memcached -vv To test your django cache config, you can use the low-level cache api. First, start up the python interpreter and load your django project settings:

Per-request cache in Django?

戏子无情 提交于 2019-11-27 01:21:06
问题 I would like to implement a decorator that provides per-request caching to any method, not just views. Here is an example use case. I have a custom tag that determines if a record in a long list of records is a "favorite". In order to check if an item is a favorite, you have to query the database. Ideally, you would perform one query to get all the favorites, and then just check that cached list against each record. One solution is to get all the favorites in the view, and then pass that set