Pyjo.Cache - Naive in-memory cache

from Pyjo.Cache import Cache

cache = Cache(max_keys=50)
cache.set('foo', 'bar')
foo = cache.get('foo')

# Or import the module, as in Google Python Style Guide

import Pyjo.Cache

cache = Pyjo.Cache.new(max_keys=50)
cache.set('foo', 'bar')
foo = cache.get('foo')

Pyjo.Cache is a naive in-memory cache with size limits.

See also

Pyjoyment, https://mojolicious.org.

Ported from Mojo::Cache of Mojolicious 9.49.

class Pyjo.Cache.Pyjo_Cache(max_keys: int = 100)[source]

Pyjo.Cache inherits all methods from Pyjo.Base and implements the following new ones.

__contains__(key: Anything) → bool[source]
boolean = 'foo' in cache

Check if a value is cached.

__len__() → int[source]
count = len(cache)

Number of cached values.

get(key: K) → V | None[source]
value = cache.get('foo')

Get cached value.

max_keys
max = cache.max_keys
cache.max_keys = 50

Maximum number of cache keys, defaults to 100. Setting the value to 0 will disable caching.

set(key: K, value: V) → Self[source]
cache = cache.set('foo', 'bar')

Set cached value.