def test_incr_decr(self):
        # Testing incr and decr operations
        from memcachepool.cache import UMemcacheCache

        # creating the cache class
        cache = UMemcacheCache('127.0.0.1:11211', {})
        cache.set('a', 1)
        cache.incr('a', 1)
        self.assertEquals(cache.get('a'), 2)
        cache.decr('a', 1)
        self.assertEquals(cache.get('a'), 1)
Ejemplo n.º 2
0
    def test_incr_decr(self):
        # Testing incr and decr operations
        from memcachepool.cache import UMemcacheCache

        # creating the cache class
        cache = UMemcacheCache('127.0.0.1:11211', {})
        cache.set('a', 1)
        cache.incr('a', 1)
        self.assertEquals(cache.get('a'), 2)
        cache.decr('a', 1)
        self.assertEquals(cache.get('a'), 1)
    def test_types(self):
        # Testing if correct types are returned
        from memcachepool.cache import UMemcacheCache

        # creating the cache class
        cache = UMemcacheCache('127.0.0.1:11211', {})
        cache.set('a', int(1))
        self.assertEquals(cache.get('a'), 1)
        self.assertTrue(isinstance(cache.get('a'), int))

        cache.set('a', long(1))
        self.assertEquals(cache.get('a'), 1)
        self.assertTrue(isinstance(cache.get('a'), long))
Ejemplo n.º 4
0
    def test_types(self):
        # Testing if correct types are returned
        from memcachepool.cache import UMemcacheCache

        # creating the cache class
        cache = UMemcacheCache('127.0.0.1:11211', {})
        cache.set('a', int(1))
        self.assertEquals(cache.get('a'), 1)
        self.assertTrue(isinstance(cache.get('a'), int))

        cache.set('a', long(1))
        self.assertEquals(cache.get('a'), 1)
        self.assertTrue(isinstance(cache.get('a'), long))
    def test_pool(self):
        from memcachepool.cache import UMemcacheCache

        # creating the cache class
        cache = UMemcacheCache('127.0.0.1:11211', {})

        # simple calls
        cache.set('a', '1')
        self.assertEqual(cache.get('a'), '1')

        # should support any type and deal with serialization
        # like python-memcached does
        cache.set('a', 1)
        self.assertEqual(cache.get('a'), 1)
        cache.delete('a')
        self.assertEqual(cache.get('a'), None)
Ejemplo n.º 6
0
def get_from_cache(cache_location, cache_params, name, key, GEVENT_MONKEY_PATCH=False):
    if GEVENT_MONKEY_PATCH:
        # Import Gevent and monkey patch
        try:
            from gevent import monkey
            monkey.patch_all()
        except:
            print "gevent monkey patch failed"
    # Import Django Cache (mozilla/django-memcached-pool)
    #from django.core.cache import cache, caches, get_cache
    #from django.core.cache import caches
    # Get Tile Cache
    cache = None
    item = None
    try:
        from umemcache import MemcachedError
        from memcachepool.cache import UMemcacheCache
        cache = UMemcacheCache(cache_location, cache_params)
        #cache = caches['tiles']
    except:
        cache = None

    if cache:
        try:
            item = cache.get(key)
	except socket_error, e:
            print e
            item = None        
        except MemcachedError, e:
            print e
            item = None
Ejemplo n.º 7
0
def connect_to_cache(name):
    # Import Gevent and monkey patch
    from gevent import monkey
    monkey.patch_all()
    # Import Django Cache (mozilla/django-memcached-pool)
    #from django.core.cache import cache, caches, get_cache
    #from django.core.cache import caches
    # Get Tile Cache
    cache = None
    try:
        from memcachepool.cache import UMemcacheCache
        cache = UMemcacheCache(settings.CACHES[name]['LOCATION'], {})
        cache.get('')
    except:
        cache = None
    return cache
Ejemplo n.º 8
0
    def test_pool(self):
        from memcachepool.cache import UMemcacheCache

        # creating the cache class
        cache = UMemcacheCache('127.0.0.1:11211', {})

        # simple calls
        cache.set('a', '1')
        self.assertEqual(cache.get('a'), '1')

        # should support any type and deal with serialization
        # like python-memcached does
        cache.set('a', 1)
        self.assertEqual(cache.get('a'), 1)
        cache.delete('a')
        self.assertEqual(cache.get('a'), None)
Ejemplo n.º 9
0
def check_cache_availability(cache_location, cache_params, GEVENT_MONKEY_PATCH=False):
    if GEVENT_MONKEY_PATCH:
        # Import Gevent and monkey patch
        try:
            from gevent import monkey
            monkey.patch_all()
        except:
            print "gevent monkey patch failed"

    available = False
    cache = None
    try:
        from umemcache import MemcachedError
        from memcachepool.cache import UMemcacheCache
        cache = UMemcacheCache(cache_location, cache_params)
        #cache = caches['tiles']
        #from django.core.cache import caches
        #tilecache = caches[cache]
        cache.get('')
        available = True
    except MemcachedError, e:
        print e
        available = False
Ejemplo n.º 10
0
def get_from_cache(name, key):
    # Import Gevent and monkey patch
    from gevent import monkey
    monkey.patch_all()
    # Import Django Cache (mozilla/django-memcached-pool)
    #from django.core.cache import cache, caches, get_cache
    #from django.core.cache import caches
    # Get Tile Cache
    cache = None
    item = None
    try:
        from memcachepool.cache import UMemcacheCache
        cache = UMemcacheCache(settings.CACHES[name]['LOCATION'], settings.CACHES[name])
        #cache = caches['tiles']
    except:
        cache = None

    if cache:
        try:
            item = cache.get(key)
        except umemcache.MemcachedError, e:
            print e
            item = None