Skip to content

[decorators] @cache never evicts; @rate_limit is process-global and raises bare ValueError #42

Closed

Description

@Shreyavemana

Summary

In nitrostack/core/additional_decorators.py, @cache never evicts entries and has no size cap, and @rate_limit raises a bare ValueError and shares one counter across all callers.

Findings

  • cache(): cache_store is a per-function dict. An expired entry is only overwritten when the same key is requested again, so high-cardinality arguments grow the dict without bound.
  • rate_limit(): one calls list per decorated function, so the limit applies to all users and instances together. It raises ValueError("Rate limit exceeded ..."), which a client cannot tell apart from a validation error, and it gives no retry hint.
  • Both are in-process only.

Proposal

  1. cache(ttl, max_size=...) with LRU eviction, plus a cache_clear() hook for tests.
  2. A typed RateLimitExceededError carrying retry_after_seconds.
  3. An optional key= callable on rate_limit for per-user limits.
  4. Document that both are per-process.

Activity

  1. added a commit that references this issue on Nov 2, 2026
  2. manish-wekan commented on Nov 2, 2026

    @manish-wekan
    Collaborator

    Fixed by #47 (merged into develop as 599315c).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions