Exemplo n.º 1
0
        def callback(*q, **kw):
            data = None
            expired  = 0
            cur_time = long(time.time())
            if key_exist(redis_session, request):
                result = get_from_key(redis_session, request)

                if result.get('expired', 0) <= cur_time:
                    # cache expired
                    data = f(*q, **kw)
                    expired = cur_time + timeout
                    set_data(redis_session, request,
                             pickle.dumps(dict(data=data, expired=expired)))
                else:
                    data = result['data']
                    expired = result['expired'] - cur_time
            else:
                data = f(*q, **kw)
                expired = cur_time + timeout
                if data:
                    set_data(redis_session, request,
                             pickle.dumps(dict(data=data, expired=expired)))
            if data and expired > 0:
                response.set_header('Cache-Control:max-age', expired)
                response.set_header('JAMDEO_HIT_CACHE', True)
                return data
Exemplo n.º 2
0
        def callback(*q, **kw):
            data = None
            expired = 0
            cur_time = long(time.time())
            if key_exist(redis_session, request):
                result = get_from_key(redis_session, request)

                if result.get('expired', 0) <= cur_time:
                    # cache expired
                    data = f(*q, **kw)
                    expired = cur_time + timeout
                    set_data(redis_session, request,
                             pickle.dumps(dict(data=data, expired=expired)))
                else:
                    data = result['data']
                    expired = result['expired'] - cur_time
            else:
                data = f(*q, **kw)
                expired = cur_time + timeout
                if data:
                    set_data(redis_session, request,
                             pickle.dumps(dict(data=data, expired=expired)))
            if data and expired > 0:
                response.set_header('Cache-Control:max-age', expired)
                response.set_header('JAMDEO_HIT_CACHE', True)
                return data
Exemplo n.º 3
0
 def wrapper(*q, **kw):
     cache_time = timeout
     key = _generate_key(request.path, request.query_string)
     data = _get(key)
     cache_tag = 'Hit Cache'
     if not data:
         cache_tag = 'Miss Cache'
         data = fn(*q, **kw)
         if isinstance(data, dict) and data.has_key(timeout_key):
             cache_time = data.get(timeout_key)
         _put(key, data, cache_time)
     response.set_header('Cache-Control: max-age', cache_time)
     response.set_header('JAMDEO_CACHE', cache_tag)
     return data
Exemplo n.º 4
0
 def wrapper(*q, **kw):
     cache_time = timeout
     key = _generate_key(request.path, request.query_string)
     data = _get(key)
     cache_tag = 'Hit Cache'
     if not data:
         cache_tag = 'Miss Cache'
         data = fn(*q, **kw)
         if isinstance(data, dict) and data.has_key(timeout_key):
             cache_time = data.get(timeout_key)
         _put(key, data, cache_time)
     response.set_header('Cache-Control: max-age', cache_time)
     response.set_header('JAMDEO_CACHE', cache_tag)
     return data