request_cache.cache.get

Here are the examples of the python api request_cache.cache.get taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

6 Examples 7

Example 1

Project: gae_bingo
Source File: cache.py
View license
def store_if_dirty():
    # Only load from request cache here -- if it hasn't been loaded from memcache previously, it's not dirty.
    bingo_cache = request_cache.cache.get(BingoCache.CACHE_KEY)
    bingo_identity_cache = request_cache.cache.get(BingoIdentityCache.key_for_identity(identity()))

    if bingo_cache:
        bingo_cache.store_if_dirty()

    if bingo_identity_cache:
        bingo_identity_cache.store_for_identity_if_dirty(identity())

Example 2

Project: gae_bingo
Source File: cache.py
View license
def store_if_dirty():
    # Only load from request cache here -- if it hasn't been loaded from memcache previously, it's not dirty.
    bingo_cache = request_cache.cache.get(BingoCache.CACHE_KEY)
    bingo_identity_cache = request_cache.cache.get(BingoIdentityCache.key_for_identity(identity()))

    if bingo_cache:
        bingo_cache.store_if_dirty()

    if bingo_identity_cache:
        bingo_identity_cache.store_for_identity_if_dirty(identity())

Example 3

Project: gae_bingo
Source File: cache.py
View license
    @staticmethod
    def fill_request_cache():
        """Load BingoCache/BingoIdentityCache from instance cache/memcache.

        This loads the shared BingoCache and the individual BingoIdentityCache
        for the current request's bingo identity and stores them both in the
        request cache.
        """
        if not request_cache.cache.get("bingo_request_cache_filled"):

            # Assume that we're going to grab both BingoCache and
            # BingoIdentityCache from memcache
            memcache_keys = [
                BingoCache.CACHE_KEY,
                BingoIdentityCache.key_for_identity(identity())
            ]

            # Try to grab BingoCache from instance cache
            bingo_instance = instance_cache.get(BingoCache.CACHE_KEY)
            if bingo_instance:
                # If successful, use instance cached version...
                request_cache.cache[BingoCache.CACHE_KEY] = bingo_instance
                # ...and don't load BingoCache from memcache
                memcache_keys.remove(BingoCache.CACHE_KEY)

            # Load necessary caches from memcache
            dict_memcache = memcache.get_multi(memcache_keys)

            # Decompress BingoCache if we loaded it from memcache
            if BingoCache.CACHE_KEY in dict_memcache:
                dict_memcache[BingoCache.CACHE_KEY] = CacheLayers.decompress(
                        dict_memcache[BingoCache.CACHE_KEY])

            # Update request cache with values loaded from memcache
            request_cache.cache.update(dict_memcache)

            if not bingo_instance:
                # And if BingoCache wasn't in the instance cache already, store
                # it with a 1-minute expiry
                instance_cache.set(BingoCache.CACHE_KEY,
                        request_cache.cache.get(BingoCache.CACHE_KEY),
                        expiry=CacheLayers.INSTANCE_SECONDS)

            request_cache.cache["bingo_request_cache_filled"] = True

Example 4

Project: gae_bingo
Source File: cache.py
View license
    @staticmethod
    def fill_request_cache():
        """Load BingoCache/BingoIdentityCache from instance cache/memcache.

        This loads the shared BingoCache and the individual BingoIdentityCache
        for the current request's bingo identity and stores them both in the
        request cache.
        """
        if not request_cache.cache.get("bingo_request_cache_filled"):

            # Assume that we're going to grab both BingoCache and
            # BingoIdentityCache from memcache
            memcache_keys = [
                BingoCache.CACHE_KEY,
                BingoIdentityCache.key_for_identity(identity())
            ]

            # Try to grab BingoCache from instance cache
            bingo_instance = instance_cache.get(BingoCache.CACHE_KEY)
            if bingo_instance:
                # If successful, use instance cached version...
                request_cache.cache[BingoCache.CACHE_KEY] = bingo_instance
                # ...and don't load BingoCache from memcache
                memcache_keys.remove(BingoCache.CACHE_KEY)

            # Load necessary caches from memcache
            dict_memcache = memcache.get_multi(memcache_keys)

            # Decompress BingoCache if we loaded it from memcache
            if BingoCache.CACHE_KEY in dict_memcache:
                dict_memcache[BingoCache.CACHE_KEY] = CacheLayers.decompress(
                        dict_memcache[BingoCache.CACHE_KEY])

            # Update request cache with values loaded from memcache
            request_cache.cache.update(dict_memcache)

            if not bingo_instance:
                # And if BingoCache wasn't in the instance cache already, store
                # it with a 1-minute expiry
                instance_cache.set(BingoCache.CACHE_KEY,
                        request_cache.cache.get(BingoCache.CACHE_KEY),
                        expiry=CacheLayers.INSTANCE_SECONDS)

            request_cache.cache["bingo_request_cache_filled"] = True

Example 5

Project: gae_bingo
Source File: cache.py
View license
    @staticmethod
    def get(key, fxn_load):
        """Load BingoCache or BingoIdentityCache into request cache.

        This will first try to prefetch the expected entities from memcache.

        If the requested BingoCache or BingoIdentityCache key still isn't in
        the current request cache after prefetching, load the key's value from
        the datastore using the passed-in loader function and update the
        current request cache.

        Args:
            key: cache key of BingoCache or specific user's BingoIdentityCache
            fxn_load: function to run that loads desired cache in the event of
                a memcache and instance cache miss during prefetch.
        """
        CacheLayers.fill_request_cache()

        if not request_cache.cache.get(key):
            request_cache.cache[key] = fxn_load()

        return request_cache.cache[key]

Example 6

Project: gae_bingo
Source File: cache.py
View license
    @staticmethod
    def get(key, fxn_load):
        """Load BingoCache or BingoIdentityCache into request cache.

        This will first try to prefetch the expected entities from memcache.

        If the requested BingoCache or BingoIdentityCache key still isn't in
        the current request cache after prefetching, load the key's value from
        the datastore using the passed-in loader function and update the
        current request cache.

        Args:
            key: cache key of BingoCache or specific user's BingoIdentityCache
            fxn_load: function to run that loads desired cache in the event of
                a memcache and instance cache miss during prefetch.
        """
        CacheLayers.fill_request_cache()

        if not request_cache.cache.get(key):
            request_cache.cache[key] = fxn_load()

        return request_cache.cache[key]