# Path: netl2api/server/utils.py
# class RedisClient(object):
#     def __init__(self, db=7, timeout=3):
#         self.host = cfg.get("redis", "host")
#         self.port = cfg.getint("redis", "port")
#         self.timeout  = timeout
#         self.redis_db = db
#         self._redis   = redis.Redis(host=self.host, port=self.port, db=self.redis_db,
#                                       socket_timeout=self.timeout)
# 
#     def get_connection(self):
#         if self._redis is None or not self._redis.ping():
#             self._redis = redis.Redis(host=self.host, port=self.port, db=self.redis_db,
#                                       socket_timeout=self.timeout)
#         return self._redis
# 
# Path: netl2api/lib/config.py
# def get_netl2server_cfg():
#     return get_cfg("netl2server", check_permission=None)
# 
# def setup_netl2server_logger(cfg):
#     return setup_logger(cfg, "netl2server")


import redis
from hashlib import sha1
from functools import wraps
from bottle import request, response
from netl2api.server.utils import RedisClient
from netl2api.lib.config import get_netl2server_cfg, setup_netl2server_logger
    from cPickle import dumps, loads
    from pickle import dumps, loads
# @author: Eduardo S. Scarpellini
# @author: Luiz Ozaki


__copyright__ = "Copyright 2012, Locaweb IDC"



try:
except ImportError:


__all__ = ["cached", "invalidate_cache"]


cfg          = get_netl2server_cfg()
logger       = setup_netl2server_logger(cfg)
cache_enable = cfg.get("cache", "enabled") == "true"
redis_cli    = RedisClient()


def cached(ttl=600):
    def proxy(f):
        @wraps(f)
        def caching(*args, **kwargs):
            if cache_enable is False:
                return f(*args, **kwargs)
            try:
                cache_db = redis_cli.get_connection()
            except Exception, e:

# Path: netl2api/server/utils.py
# class RedisClient(object):
#     def __init__(self, db=7, timeout=3):
#         self.host = cfg.get("redis", "host")
#         self.port = cfg.getint("redis", "port")
#         self.timeout  = timeout
#         self.redis_db = db
#         self._redis   = redis.Redis(host=self.host, port=self.port, db=self.redis_db,
#                                       socket_timeout=self.timeout)
# 
#     def get_connection(self):
#         if self._redis is None or not self._redis.ping():
#             self._redis = redis.Redis(host=self.host, port=self.port, db=self.redis_db,
#                                       socket_timeout=self.timeout)
#         return self._redis
# 
# Path: netl2api/lib/config.py
# def get_netl2server_cfg():
#     return get_cfg("netl2server", check_permission=None)
# 
# def setup_netl2server_logger(cfg):
#     return setup_logger(cfg, "netl2server")


# Path: netl2api/server/http_cache.py
import redis
from hashlib import sha1
from functools import wraps
from bottle import request, response
from netl2api.server.utils import RedisClient
from netl2api.lib.config import get_netl2server_cfg, setup_netl2server_logger
    from cPickle import dumps, loads
    from pickle import dumps, loads

# @author: Eduardo S. Scarpellini
# @author: Luiz Ozaki


__copyright__ = "Copyright 2012, Locaweb IDC"



try:
except ImportError:


__all__ = ["cached", "invalidate_cache"]


cfg          = get_netl2server_cfg()
logger       = setup_netl2server_logger(cfg)
cache_enable = cfg.get("cache", "enabled") == "true"
redis_cli    = RedisClient()


def cached(ttl=600):
    def proxy(f):
        @wraps(f)
        def caching(*args, **kwargs):
            if cache_enable is False:
                return f(*args, **kwargs)
            try:
                cache_db = redis_cli.get_connection()
            except Exception, e:

                logger.exception("Error in redis_cli connection (cache database)")