python - Django API caching, how to check it's setup correctly -
whats best way check if have setup caching correctly tastypie? have followed documentation on this:
in settings added this:
caches = { 'default': { 'backend': 'django.core.cache.backends.locmem.locmemcache', 'timeout': 60 }, 'resources': { 'backend': 'django.core.cache.backends.locmem.locmemcache', 'timeout': 60 } }
in resource added:
class incentiveresource(modelresource): class meta: queryset = incentive.objects.all() resource_name = 'incentive' allowed_methods = ['get'] always_return_data = true cache = simplecache(cache_name='resources', timeout=10)
just write , run simple test check resources
cache working:
from django.test import testcase tastypie.cache import simplecache class cachetestcase(testcase): cache_name = 'resources' def test_cache(self): simple_cache = simplecache(cache_name=self.cache_name) simple_cache.set('foo', 'bar', 60) simple_cache.set('moof', 'baz', 1) self.assertequal(simple_cache.get('foo'), 'bar') self.assertequal(simple_cache.get('moof'), 'baz') self.assertequal(simple_cache.get(''), none)
partially taken tastypie tests modifications.
Comments
Post a Comment