Beispiel #1
0
def _register_backends():
    # NOTE(morganfainberg): This function exists to ensure we do not try and
    # register the backends prior to the configuration object being fully
    # available.  We also need to ensure we do not register a given backend
    # more than one time.  All backends will be prefixed with openstack.kvs
    # as the "short" name to reference them for configuration purposes.  This
    # function is used in addition to the pre-registered backends in the
    # __init__ file for the KVS system.
    global BACKENDS_REGISTERED

    if not BACKENDS_REGISTERED:
        prefix = 'openstack.kvs.%s'
        for backend in CONF.kvs.backends:
            module, cls = backend.rsplit('.', 1)
            backend_name = prefix % cls
            LOG.debug(('Registering Dogpile Backend %(backend_path)s as '
                       '%(backend_name)s'),
                      {'backend_path': backend, 'backend_name': backend_name})
            region.register_backend(backend_name, module, cls)
        BACKENDS_REGISTERED = True
def _register_backends():
    # NOTE(morganfainberg): This function exists to ensure we do not try and
    # register the backends prior to the configuration object being fully
    # available.  We also need to ensure we do not register a given backend
    # more than one time.  All backends will be prefixed with openstack.kvs
    # as the "short" name to reference them for configuration purposes.  This
    # function is used in addition to the pre-registered backends in the
    # __init__ file for the KVS system.
    global BACKENDS_REGISTERED

    if not BACKENDS_REGISTERED:
        prefix = 'openstack.kvs.%s'
        for backend in CONF.kvs.backends:
            module, cls = backend.rsplit('.', 1)
            backend_name = prefix % cls
            LOG.debug(('Registering Dogpile Backend %(backend_path)s as '
                       '%(backend_name)s'),
                      {'backend_path': backend, 'backend_name': backend_name})
            region.register_backend(backend_name, module, cls)
        BACKENDS_REGISTERED = True
Beispiel #3
0
    def delete(self, key):
        self._cache_dictionary.pop(key, None)

    @property
    def _cache_dictionary(self):
        """Return the cache dictionary linked to the current Session."""

        sess = self.scoped_session()
        try:
            cache_dict = sess._cache_dictionary
        except AttributeError:
            sess._cache_dictionary = cache_dict = {}
        return cache_dict


register_backend("sqlalchemy.session", __name__, "ScopedSessionBackend")


if __name__ == "__main__":
    from .environment import Session, regions
    from .caching_query import FromCache
    from dogpile.cache import make_region

    # set up a region based on the ScopedSessionBackend,
    # pointing to the scoped_session declared in the example
    # environment.
    regions["local_session"] = make_region().configure(
        "sqlalchemy.session", arguments={"scoped_session": Session}
    )

    from .model import Person
Beispiel #4
0
from dogpile.cache.region import register_backend

__version__ = "0.3.2"

# name, modulepath, objname
register_backend(
    "dogpile_backend_redis_advanced",
    "dogpile_backend_redis_advanced.cache.backends.redis_advanced",
    "RedisAdvancedBackend",
)
register_backend(
    "dogpile_backend_redis_advanced_hstore",
    "dogpile_backend_redis_advanced.cache.backends.redis_advanced",
    "RedisAdvancedHstoreBackend",
)
Beispiel #5
0
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from dogpile.cache import region

from keystone.common.kvs.core import *  # flake8: noqa
from keystone.common.kvs.legacy import Base, DictKvs, INMEMDB  # flake8: noqa


# NOTE(morganfainberg): Provided backends are registered here in the __init__
# for the kvs system.  Any out-of-tree backends should be registered via the
# ``backends`` option in the ``[kvs]`` section of the Keystone configuration
# file.
region.register_backend(
    'openstack.kvs.Memory',
    'keystone.common.kvs.backends.inmemdb',
    'MemoryBackend')

region.register_backend(
    'openstack.kvs.Memcached',
    'keystone.common.kvs.backends.memcached',
    'MemcachedBackend')
Beispiel #6
0
# Copyright 2013 Metacloud, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from dogpile.cache import region

from keystone.common.kvs.core import *  # flake8: noqa
from keystone.common.kvs.legacy import Base, DictKvs, INMEMDB  # flake8: noqa

# NOTE(morganfainberg): Provided backends are registered here in the __init__
# for the kvs system.  Any out-of-tree backends should be registered via the
# ``backends`` option in the ``[kvs]`` section of the Keystone configuration
# file.
region.register_backend('openstack.kvs.Memory',
                        'keystone.common.kvs.backends.inmemdb',
                        'MemoryBackend')

region.register_backend('openstack.kvs.Memcached',
                        'keystone.common.kvs.backends.memcached',
                        'MemcachedBackend')
Beispiel #7
0
from dogpile.cache.region import register_backend

register_backend("dogpile.cache.null", "dogpile.cache.backends.null",
                 "NullBackend")
register_backend("dogpile.cache.dbm", "dogpile.cache.backends.file",
                 "DBMBackend")
register_backend("dogpile.cache.pylibmc", "dogpile.cache.backends.memcached",
                 "PylibmcBackend")
register_backend("dogpile.cache.bmemcached",
                 "dogpile.cache.backends.memcached", "BMemcachedBackend")
register_backend("dogpile.cache.memcached", "dogpile.cache.backends.memcached",
                 "MemcachedBackend")
register_backend("dogpile.cache.memory", "dogpile.cache.backends.memory",
                 "MemoryBackend")
register_backend("dogpile.cache.memory_pickle",
                 "dogpile.cache.backends.memory", "MemoryPickleBackend")
register_backend("dogpile.cache.redis", "dogpile.cache.backends.redis",
                 "RedisBackend")
    def delete(self, key):
        self._cache_dictionary.pop(key, None)

    @property
    def _cache_dictionary(self):
        """Return the cache dictionary linked to the current Session."""

        sess = self.scoped_session()
        try:
            cache_dict = sess._cache_dictionary
        except AttributeError:
            sess._cache_dictionary = cache_dict = {}
        return cache_dict

register_backend("sqlalchemy.session", __name__, "ScopedSessionBackend")


if __name__ == '__main__':
    from .environment import Session, regions
    from .caching_query import FromCache
    from dogpile.cache import make_region

    # set up a region based on the ScopedSessionBackend,
    # pointing to the scoped_session declared in the example
    # environment.
    regions['local_session'] = make_region().configure(
        'sqlalchemy.session',
        arguments={
            "scoped_session": Session
        }
Beispiel #9
0
from dogpile.cache.region import register_backend

register_backend("dogpile.cache.null", "dogpile.cache.backends.null", "NullBackend")
register_backend("dogpile.cache.dbm", "dogpile.cache.backends.file", "DBMBackend")
register_backend("dogpile.cache.pylibmc", "dogpile.cache.backends.memcached", "PylibmcBackend")
register_backend("dogpile.cache.bmemcached", "dogpile.cache.backends.memcached", "BMemcachedBackend")
register_backend("dogpile.cache.memcached", "dogpile.cache.backends.memcached", "MemcachedBackend")
register_backend("dogpile.cache.memory", "dogpile.cache.backends.memory", "MemoryBackend")
register_backend("dogpile.cache.memory_pickle", "dogpile.cache.backends.memory", "MemoryPickleBackend")
register_backend("dogpile.cache.redis", "dogpile.cache.backends.redis", "RedisBackend")
Beispiel #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from dogpile.cache.backends.redis import RedisBackend
from dogpile.cache.api import NO_VALUE
from dogpile.cache.region import register_backend

__all__ = 'CustomRedisBackend',

register_backend('yosaipy2.cache.redis', 'yosaipy2.core.cache.backend',
                 'CustomRedisBackend')


class CustomRedisBackend(RedisBackend):
    def __init__(self, arguments):
        super(CustomRedisBackend, self).__init__(arguments)

    def get(self, key):
        value = self.client.get(key)
        if value is None:
            return NO_VALUE
        return value

    def get_multi(self, keys):
        if not keys:
            return []
        values = self.client.mget(keys)
        return [v if v is not None else NO_VALUE for v in values]

    def set(self, key, value):
        if self.redis_expiration_time:
            self.client.setex(key, self.redis_expiration_time, value)
Beispiel #11
0
import unittest
from pyramid import testing
from testconfig import config
from dogpile.cache.api import CacheBackend, NO_VALUE
from dogpile.cache.region import register_backend
from augias.models import DBSession, Base
from augias.utils import cache


class NullCache(CacheBackend):
    get = lambda *_: NO_VALUE
    __init__ = set = delete = lambda *_: None


register_backend("null", "augias.tests", "NullCache")


class TestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        from sqlalchemy import create_engine

        try:
            cls.db_url = config["db"]["url"]
        except KeyError:
            cls.db_url = "sqlite://"
        cls.engine = create_engine(cls.db_url)

        if not "backend" in cache.__dict__:
            cache.configure("null")