cache

In-memory cache for successful Scholar answers.

Every uncached call costs a 5-15 s delay and one or more requests that count towards Scholar’s bot detection. Agents repeat lookups (the same paper, the same query), so answering those from memory is faster and makes a block less likely. Only successful results are stored; errors are never cached.

class google_scholar_search_mcp.cache.TTLCache(ttl_seconds=3600.0, max_entries=256)[source]

Bases: object

A small thread-safe LRU cache whose entries expire.

property enabled: bool

Whether the cache stores anything.

get(key)[source]

Look up a fresh entry.

Parameters:

key (Hashable) – Cache key.

Returns:

Any | None – The stored value, or None if absent or expired.

Return type:

Any | None

set(key, value)[source]

Store a value (no-op while the cache is disabled).

Parameters:
  • key (Hashable) – Cache key.

  • value (Any) – Value to keep.

clear()[source]

Drop all entries and reset the counters.

google_scholar_search_mcp.cache.normalize(text)[source]

Normalize free text for use in a cache key.

Parameters:

text (str | None) – Query, title or id.

Returns:

str – Lower-cased with collapsed whitespace; empty for None.

Return type:

str