示例#1
0
        def __responseCache(self, **keywords):
    
            if (not keywords):
                raise TypeError, 'Please specify the argument.'

            request = keywords['values']
            expiresTime = keywords['expires'] if (keywords.has_key('expires')) else expires 

            query = '&'.join([key + '=' + str(request[key]) for key in sorted(request.keys())])
            cacheKey = method + '=' + md5(query).hexdigest()

            cacheManager = CacheManager()
            if (cacheManager.hasCache(cacheKey)):
                cache = cacheManager.getCache(cacheKey)
                if (cache.isExpires()):
                    response = cache.getContent()
                else:
                    response = _responseCached(cacheKey, function(self, request), expiresTime)
            else:
                response = _responseCached(cacheKey, function(self, request), expiresTime)

            return response
示例#2
0
    def _responseCached(cacheKey, response, expires): 
        if (response.getCode() in [200, 300]):
            cacheManager = CacheManager()
            cacheManager.addCache(cacheKey, Cache(content=response, expires=expires))

        return response