Beispiel #1
0
def get_locks_cache():
    """Get locks shared cache"""
    try:
        locks_cache = _LOCAL.locks_cache
    except AttributeError:
        manager = cache.CacheManager(**cache.cache_regions['persistent'])
        locks_cache = _LOCAL.locks_cache = manager.get_cache('PyAMS::locks')
    return locks_cache
Beispiel #2
0
def get_progress_cache():
    """Get cache storing tasks progress"""
    try:
        local_cache = _LOCAL.progress_cache
    except AttributeError:
        manager = cache.CacheManager(**cache.cache_regions['default'])
        local_cache = _LOCAL.progress_cache = manager.get_cache(
            PROGRESS_CACHE_NAME)
    return local_cache
Beispiel #3
0
def get_tasks_cache():
    """Get cache storing tasks list"""
    try:
        tasks_cache = _LOCAL.running_tasks_cache
    except AttributeError:
        manager = cache.CacheManager(**cache.cache_regions['persistent'])
        tasks_cache = _LOCAL.running_tasks_cache = manager.get_cache(
            PROGRESS_CACHE_NAME)
    return tasks_cache
Beispiel #4
0
 def __init__(self, cache):
     if not has_beaker:
         raise exceptions.RuntimeException(
             "Can't initialize Beaker plugin; Beaker is not installed.")
     global _beaker_cache
     if _beaker_cache is None:
         if 'manager' in cache.template.cache_args:
             _beaker_cache = cache.template.cache_args['manager']
         else:
             _beaker_cache = beaker_cache.CacheManager()
     super(BeakerCacheImpl, self).__init__(cache)
Beispiel #5
0
    def __init__(self, cache):
        global _beaker_cache
        if _beaker_cache is None:
            try:
                from beaker import cache as beaker_cache
            except ImportError, e:
                raise exceptions.RuntimeException(
                    "the Beaker package is required to use cache "
                    "functionality.")

            _beaker_cache = beaker_cache.CacheManager()
Beispiel #6
0
    def __init__(self, cache):
        global _beaker_cache
        if _beaker_cache is None:
            try:
                from beaker import cache as beaker_cache
            except ImportError, e:
                raise exceptions.RuntimeException(
                    "the Beaker package is required to use cache "
                    "functionality.")

            if 'manager' in cache.template.cache_args:
                _beaker_cache = cache.template.cache_args['manager']
            else:
                _beaker_cache = beaker_cache.CacheManager()
Beispiel #7
0
    def _get_cache(self, defname, type=None, **kw):
        global cache
        if not cache:
            try:
                from beaker import cache as beaker_cache
                cache = beaker_cache.CacheManager()
            except ImportError:
                # keep a fake cache around so subsequent
                # calls don't attempt to re-import
                cache = BeakerMissing()

        if type == 'memcached':
            type = 'ext:memcached'
        if not type:
            (type, kw) = self.def_regions.get(defname, ('memory', {}))
        else:
            self.def_regions[defname] = (type, kw)
        return cache.get_cache(self.id, type=type, **kw)
Beispiel #8
0
from mako import exceptions

try:
    from beaker import cache
    cache = cache.CacheManager()
except ImportError:
    cache = None

class Cache(object):
    def __init__(self, id, starttime):
        self.id = id
        self.starttime = starttime
        self.def_regions = {}
        
    def put(self, key, value, **kwargs):
        defname = kwargs.pop('defname', None)
        expiretime = kwargs.pop('expiretime', None)
        createfunc = kwargs.pop('createfunc', None)
        
        self._get_cache(defname, **kwargs).put_value(key, starttime=self.starttime, expiretime=expiretime)
        
    def get(self, key, **kwargs):
        defname = kwargs.pop('defname', None)
        expiretime = kwargs.pop('expiretime', None)
        createfunc = kwargs.pop('createfunc', None)
        
        return self._get_cache(defname, **kwargs).get_value(key, starttime=self.starttime, expiretime=expiretime, createfunc=createfunc)
        
    def invalidate(self, key, **kwargs):
        defname = kwargs.pop('defname', None)
        expiretime = kwargs.pop('expiretime', None)
Beispiel #9
0
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
"""
SQLAlchemy Metadata and Session object
"""

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
from beaker import cache

from rhodecode.lib import caching_query

# Beaker CacheManager.  A home base for cache configurations.
cache_manager = cache.CacheManager()

__all__ = ['Base', 'Session']
#
# SQLAlchemy session manager. Updated by model.init_model()
#
Session = scoped_session(
    sessionmaker(
        query_cls=caching_query.query_callable(cache_manager),
        expire_on_commit=True,
    ))

# The declarative Base
Base = declarative_base()

#to use cache use this in query