3
我正在看tastypie caching docs並試圖建立自己的簡單緩存的事情,但緩存似乎並沒有被調用。當我訪問http://localhost:8000/api/poll/?format=json時,我得到了我的tastypie生成的json,但是我沒有從緩存類中得到輸出。爲什麼我的tastypie緩存沒有被調用?
from tastypie.resources import ModelResource
from tastypie.cache import NoCache
from .models import Poll
class JSONCache(NoCache):
def _load(self):
print 'loading cache'
data_file = open(settings.TASTYPIE_JSON_CACHE, 'r')
return json.load(data_file)
def _save(self, data):
print 'saving to cache'
data_file = open(settings.TASTYPIE_JSON_CACHE, 'w')
return json.dump(data, data_file)
def get(self, key):
print 'jsoncache.get'
data = self._load()
return data.get(key, None)
def set(self, key, value, timeout=60):
print 'jsoncache.set'
data = self._load()
data[key] = value
self._save(data)
class PollResource(ModelResource):
class Meta:
queryset = Poll.objects.all()
resource_name = 'poll'
cache = JSONCache()
我正在使用tastypie.in該案件不起作用 – RahulG 2015-05-20 11:30:49