INNER CODE UNIT · Python

_get_sliding_window_info

alisaifee/limits · limits/aio/storage/memcached/__init__.py:176

    async def _get_sliding_window_info(
        self, previous_key: str, current_key: str, expiry: int, now: float
    ) -> tuple[int, float, int, float]:
        result = await self.bridge.get_many([previous_key, current_key])

        previous_count = result.get(previous_key.encode("utf-8"), 0)
        current_count = result.get(current_key.encode("utf-8"), 0)

        if previous_count == 0:
            previous_ttl = float(0)
        else:
            previous_ttl = (1 - (((now - expiry) / expiry) % 1)) * expiry
        current_ttl = (1 - ((now / expiry) % 1)) * expiry + expiry

        return previous_count, previous_ttl, current_count, current_ttl

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…