priority: high

status: open

title: Implement the search cache key

type: feature


current_content:
"""Cache key derivation for the search result cache."""

def cache_key(params):
    """A stable key for a parameter dict."""
    raise NotImplementedError

note: hidden tests also run at verification time and are not shown

service: search

spec:
Implement cache_key(params) returning a string.

The search result cache is keyed on the query parameters. Two calls with the
same parameters must produce the same key regardless of the order the keys
were inserted into the dict, because callers build them in different orders
and a mismatch silently halves the hit rate.

Different parameters must produce different keys. A parameter explicitly set
to None is not the same request as one that was never supplied. Values may be
strings, numbers, booleans or None.


content:
"""Cache key derivation for the search result cache."""
import json

def cache_key(params):
    """A stable key for a parameter dict."""
    return json.dumps(params, sort_keys=True, separators=(',', ':'),
                      default=str)

next: run_exercise_tests to execute it


note: all visible tests pass; hidden tests also ran and are not shown