Пример #1
0
    def load(cls, key):
        if not cls.group:
            raise ValueError()

        # Try retrieve from memory cache
        item = cache[cls.group].get(key)

        if item:
            # Return `item` from cache
            return item

        # Otherwise, try retrieve from disk
        if not os.path.exists(cls.group_path()):
            os.makedirs(cls.group_path())

        path = cls.item_path(key)

        if not FileIO.exists(path):
            return None

        # Load data from disk
        try:
            data = FileIO.read(path)
        except Exception, ex:
            log.warn('Unable to load "%s" (%s)', path, ex)
            return None
Пример #2
0
    def save(self):
        if not self.group:
            raise ValueError()

        # Save to memory cache
        cache[self.group][self.key] = self

        # Save to disk
        if not os.path.exists(self.group_path()):
            os.makedirs(self.group_path())

        FileIO.write(self.item_path(self.key), jsonpickle.encode(self))
Пример #3
0
    def delete(cls, key):
        if not cls.group:
            raise ValueError()

        # Delete from memory cache
        cache[cls.group].delete(key)

        # Delete from disk
        if not os.path.exists(cls.group_path()):
            os.makedirs(cls.group_path())

        path = cls.item_path(key)

        if not FileIO.exists(path):
            return

        FileIO.delete(path)