Exemplo n.º 1
0
    def __getitem__(self, key):
        try:
            entry = self._cache[key]
            cache_counter.inc_hits(self._cache_name)
        except KeyError:
            cache_counter.inc_misses(self._cache_name)
            raise

        if self._reset_expiry_on_get:
            entry.time = self._clock.time_msec()

        return entry.value
Exemplo n.º 2
0
    def __getitem__(self, key):
        try:
            entry = self._cache[key]
            cache_counter.inc_hits(self._cache_name)
        except KeyError:
            cache_counter.inc_misses(self._cache_name)
            raise

        if self._reset_expiry_on_get:
            entry.time = self._clock.time_msec()

        return entry.value
Exemplo n.º 3
0
    def get_rooms_changed(self, store, room_ids, key):
        """Returns subset of room ids that have had new receipts since the
        given key. If the key is too old it will just return the given list.
        """
        if key > (yield self._get_earliest_key(store)):
            keys = self._cache.keys()
            i = keys.bisect_right(key)

            result = set(self._cache[k]
                         for k in keys[i:]).intersection(room_ids)

            cache_counter.inc_hits(self.name)
        else:
            result = room_ids
            cache_counter.inc_misses(self.name)

        defer.returnValue(result)
Exemplo n.º 4
0
    def get_rooms_changed(self, store, room_ids, key):
        """Returns subset of room ids that have had new receipts since the
        given key. If the key is too old it will just return the given list.
        """
        if key > (yield self._get_earliest_key(store)):
            keys = self._cache.keys()
            i = keys.bisect_right(key)

            result = set(
                self._cache[k] for k in keys[i:]
            ).intersection(room_ids)

            cache_counter.inc_hits(self.name)
        else:
            result = room_ids
            cache_counter.inc_misses(self.name)

        defer.returnValue(result)
Exemplo n.º 5
0
    def get_entities_changed(self, entities, stream_pos):
        """Returns subset of entities that have had new things since the
        given position. If the position is too old it will just return the given list.
        """
        assert type(stream_pos) is int

        if stream_pos >= self._earliest_known_stream_pos:
            keys = self._cache.keys()
            i = keys.bisect_right(stream_pos)

            result = set(self._cache[k]
                         for k in keys[i:]).intersection(entities)

            cache_counter.inc_hits(self.name)
        else:
            result = entities
            cache_counter.inc_misses(self.name)

        return result
Exemplo n.º 6
0
    def get_entities_changed(self, entities, stream_pos):
        """Returns subset of entities that have had new things since the
        given position. If the position is too old it will just return the given list.
        """
        assert type(stream_pos) is int

        if stream_pos >= self._earliest_known_stream_pos:
            keys = self._cache.keys()
            i = keys.bisect_right(stream_pos)

            result = set(
                self._cache[k] for k in keys[i:]
            ).intersection(entities)

            cache_counter.inc_hits(self.name)
        else:
            result = entities
            cache_counter.inc_misses(self.name)

        return result
Exemplo n.º 7
0
    def has_entity_changed(self, entity, stream_pos):
        """Returns True if the entity may have been updated since stream_pos
        """
        assert type(stream_pos) is int

        if stream_pos < self._earliest_known_stream_pos:
            cache_counter.inc_misses(self.name)
            return True

        latest_entity_change_pos = self._entity_to_key.get(entity, None)
        if latest_entity_change_pos is None:
            cache_counter.inc_hits(self.name)
            return False

        if stream_pos < latest_entity_change_pos:
            cache_counter.inc_misses(self.name)
            return True

        cache_counter.inc_hits(self.name)
        return False
Exemplo n.º 8
0
    def has_entity_changed(self, entity, stream_pos):
        """Returns True if the entity may have been updated since stream_pos
        """
        assert type(stream_pos) is int

        if stream_pos < self._earliest_known_stream_pos:
            cache_counter.inc_misses(self.name)
            return True

        latest_entity_change_pos = self._entity_to_key.get(entity, None)
        if latest_entity_change_pos is None:
            cache_counter.inc_hits(self.name)
            return False

        if stream_pos < latest_entity_change_pos:
            cache_counter.inc_misses(self.name)
            return True

        cache_counter.inc_hits(self.name)
        return False