Example #1
0
    def setValue(self, key, value, timeout=None):
        """
        Caches the inputted key and value to this instance.

        :param      key     | <hashable>
                    value   | <variant>
        """
        if not self.isEnabled():
            return

        timeout = timeout or self.timeout()

        with WriteLocker(self._cacheLock):
            self._cache[key] = value
            self._expiresAt[key] = datetime.datetime.now(
            ) + datetime.timedelta(seconds=timeout)

    def value(self, key, default=None):
        """
        Returns the value for the cached key for this instance.

        :return     <variant>
        """
        with ReadLocker(self._cacheLock):
            return self._cache.get(key)


# create a basic cache object
DataCache.registerAddon('Basic', BasicCache)
Example #2
0
        :return     <bool>
        """
        return self._client.exists(self.__key(key))

    def setValue(self, key, value, timeout=None):
        """
        Caches the inputted key and value to this instance.

        :param      key     | <hashable>
                    value   | <variant>
        """
        key = self.__key(key)
        self._client.set(key, cPickle.dumps(value))
        self._client.expire(key, int(timeout or self.timeout()))

    def value(self, key, default=None):
        """
        Returns the value for the cached key for this instance.

        :return     <variant>
        """
        key = self.__key(key)
        value = self._client.get(key)
        if value is not None:
            return cPickle.loads(value)
        else:
            return default

# create a basic cache object
DataCache.registerAddon('Redis', RedisCache)
Example #3
0
        with ReadLocker(self._cacheLock):
            return key in self._cache

    def setValue(self, key, value, timeout=None):
        """
        Caches the inputted key and value to this instance.

        :param      key     | <hashable>
                    value   | <variant>
        """
        if not self.isEnabled():
            return

        timeout = timeout or self.timeout()

        with WriteLocker(self._cacheLock):
            self._cache[key] = value
            self._expiresAt[key] = datetime.datetime.now() + datetime.timedelta(seconds=timeout)

    def value(self, key, default=None):
        """
        Returns the value for the cached key for this instance.

        :return     <variant>
        """
        with ReadLocker(self._cacheLock):
            return self._cache.get(key)

# create a basic cache object
DataCache.registerAddon('Basic', BasicCache)
Example #4
0
        """
        return self._client.exists(self.__key(key))

    def setValue(self, key, value, timeout=None):
        """
        Caches the inputted key and value to this instance.

        :param      key     | <hashable>
                    value   | <variant>
        """
        key = self.__key(key)
        self._client.set(key, cPickle.dumps(value))
        self._client.expire(key, int(timeout or self.timeout()))

    def value(self, key, default=None):
        """
        Returns the value for the cached key for this instance.

        :return     <variant>
        """
        key = self.__key(key)
        value = self._client.get(key)
        if value is not None:
            return cPickle.loads(value)
        else:
            return default


# create a basic cache object
DataCache.registerAddon('Redis', RedisCache)