4👍
Just write and run a simple test to check that your resources
cache is working:
from django.test import TestCase
from 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 from the tastypie tests with some modifications.
0👍
Given you followed the cache docs to the letter And tastypie has an extensive testsuite When their CI builds succeed Then I would expect it to work.
To double check you could:
Pick a resource you think should be cached and pound its URL with a tool like ab. If your config is right, your database load shouldn’t go up. You could put this in a last step of your deployment scripts together with the other tests that test your whole stack.
Or put it in a tiny test in your project, like alecxe suggests, that just asserts that your configured cache is indeed used.
- [Django]-How to filter generic foreign keys?
- [Django]-Storing logic inside database
- [Django]-Install hstore extension for django tests
- [Django]-Production django server throwing "NoReverseMatch" while rendering, works on development
- [Django]-Pass field value to custom layout.Field
Source:stackexchange.com