コード例 #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)
コード例 #2
0
ファイル: rediscache.py プロジェクト: SPRIME01/orb
        :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)
コード例 #3
0
ファイル: basiccache.py プロジェクト: SPRIME01/orb
        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)
コード例 #4
0
ファイル: rediscache.py プロジェクト: SPRIME01/orb
        """
        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)