Skip to content

@cache: warn about arguments that cannot cache (no ttl sends an empty Cache-Control; no_store with ttl) #328

Description

@allen0099

Problem

Some @cache argument combinations cannot cache anything, and they are accepted silently.

  • @cache() with no ttl and no directive: nothing is stored, and the response carries an empty Cache-Control: header.
    GET /a -> {"n": 1}  Cache-Control: ''
    GET /a -> {"n": 2}  Cache-Control: ''
    
  • @cache(no_store=True, ttl=60): the two arguments contradict each other.

Proposal

  • Do not send an empty Cache-Control header.
  • At decoration time, warn (or raise CacheXError) when the arguments leave nothing to cache or contradict each other, for example no_store together with ttl. The validation that already exists for stale / stale_ttl is the model to follow.

Activity

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

    bugSomething isn't workingdeveloper-experienceSurprising behaviour, missing warnings or unclear errors for library usershttp-cacheThe @cache decorator, cache keys and Cache-Control handling

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions