def test_invalidates_cache_with_cached_call(self): TIMEOUT = 22 key = "cache_key" @memoize(key=key, time=TIMEOUT) def memoized(): return "ok" # memoized() returns an instance of CachedCall. @invalidates_cache(memoized) def invalidates(): pass cc = memoized() # Execute the CachedCall to set the cache cc() self.assertEqual('"ok"', cache.get(key)) invalidates() self.assertEqual(None, cache.get(key)) self.assertEqual(DoesNotExist, CachedCall.inprocess_cache.get(key))
def api_upload(request): content_type = request.META.get('CONTENT_TYPE', '') url = '' filedata = None if 'file' in request.FILES: filedata = "".join(request.FILES['file'].chunks()) elif content_type.startswith('application/json'): json = util.loads(request.body) url = json.get('url', '').strip() filedata = _fetch_url(url) elif content_type.startswith('application/base64-png'): token = 'data:image/png;base64,' header, data = request.body.split(',', 2) if not header.startswith('data:') or not 'image/png' in header or not 'base64' in header: return {'success': False, 'code': 'unknown', 'reason': 'Missing data url header.'} else: filedata = b64decode(data) if filedata: ret = _got_imagedata(filedata, request, url=url) from canvas.cache_patterns import cache from canvas.models import Content util.papertrail.debug('UPLOADS: _got_imagedata, actual cache is {} for content ID {}'.format(cache.get('content:%s:full_details_v26' % ret['content']['id']), ret['content']['id'])) util.papertrail.debug('UPLOADS: _got_imagedata, actual content object for ID {} exists: {}'.format(ret['content']['id'], Content.all_objects.filter(id=ret['content']['id']).exists())) util.papertrail.debug('UPLOADS: _got_imagedata: {} {}'.format(ret.get('success'), ret['content']['id'])) return ret else: raise ServiceError("No file or url.")