{"id":7062,"library":"cachebox","title":"Cachebox","description":"Cachebox (v5.2.3) is a high-performance Python caching and memoization library, distinguished by its core implementation in Rust. It offers various thread-safe caching algorithms like LRU, FIFO, LFU, MRU, RR, TTL, and VTTL, designed for significantly faster execution and lower memory footprint compared to pure Python alternatives. The library is actively maintained and receives regular updates.","status":"active","version":"5.2.3","language":"en","source_language":"en","source_url":"https://github.com/awolverp/cachebox","tags":["caching","memoization","performance","rust","decorator","lru-cache","ttl-cache"],"install":[{"cmd":"pip install cachebox","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"symbol":"cached","correct":"from cachebox import cached"},{"symbol":"LRUCache","correct":"from cachebox import LRUCache"},{"symbol":"TTLCache","correct":"from cachebox import TTLCache"},{"note":"`cachedmethod` was deprecated in v5.1.0; use `cached` and pass a custom `key_maker` if needed.","wrong":"from cachebox import cachedmethod","symbol":"cachedmethod","correct":"from cachebox import cached"}],"quickstart":{"code":"from cachebox import cached, LRUCache\nimport time\n\n# Using the cached decorator with an LRU cache\n@cached(LRUCache(maxsize=128))\ndef fetch_expensive_data(item_id: int) -> str:\n    \"\"\"Simulates an expensive data fetch.\"\"\"\n    print(f\"Fetching data for item_id: {item_id}...\")\n    time.sleep(0.1) # Simulate network/computation delay\n    return f\"Data for {item_id}\"\n\nprint(fetch_expensive_data(1))\nprint(fetch_expensive_data(2))\nprint(fetch_expensive_data(1)) # This will be cached\n\n# Using a cache instance directly\nmy_cache = LRUCache(maxsize=10)\nmy_cache[\"key1\"] = \"value1\"\nprint(my_cache.get(\"key1\"))\n\n# Check if a function is cached\nprint(f\"Is fetch_expensive_data cached? {cached.is_cached(fetch_expensive_data)}\")\n","lang":"python","description":"This quickstart demonstrates how to use the `@cached` decorator for memoization with a `LRUCache` and how to interact with a cache instance directly like a dictionary. It also shows how to check if a function is cached."},"warnings":[{"fix":"Replace `@cachebox.cachedmethod` with `@cachebox.cached` and implement a `key_maker` if the `self` parameter needs to be ignored for hashing.","message":"The `cachedmethod` decorator was deprecated in `cachebox` v5.1.0. It is recommended to use the `cached` decorator instead, optionally providing a custom `key_maker` function for methods.","severity":"deprecated","affected_versions":">=5.1.0"},{"fix":"Upgrade your Python environment to 3.9 or newer. The library officially supports Python 3.9+.","message":"Starting with `cachebox` v5.0.2, support for Python 3.8 was dropped. Users on Python 3.8 will not be able to install or use newer versions of `cachebox`.","severity":"breaking","affected_versions":">=5.0.2"},{"fix":"If experiencing runtime errors or performance degradation on `musl` Linux with `cachebox` v5.2.0, upgrade to v5.2.1 or newer.","message":"Version 5.2.0 introduced `mimalloc` as the default allocator for some platforms, which caused issues on `musl` Linux systems. This was addressed in v5.2.1 with the addition of `local_dynamic_tls` mimalloc feature.","severity":"gotcha","affected_versions":"5.2.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Update your code to use the `cached` decorator instead. For instance methods, if you need to ignore `self` for key generation, provide a `key_maker` function. Example: `@cached(cachebox.LRUCache(128), key_maker=lambda args, kwargs: args[1:])`.","cause":"Attempting to use the `cachedmethod` decorator after it was deprecated in `cachebox` v5.1.0.","error":"NameError: name 'cachedmethod' is not defined"},{"fix":"Ensure you are using `cachebox` v5.2.1 or newer, which includes a fix for `musl` compatibility related to `mimalloc`. If the issue persists, consider trying a different Python environment or consulting `cachebox`'s GitHub issues for `musl`-specific build instructions.","cause":"This error can occur on `musl`-based Linux distributions (like Alpine Linux) when `cachebox` v5.2.0 or specific `mimalloc` configurations are used, leading to issues with dynamic linking or memory allocation.","error":"ImportError: cannot import name '...' from 'cachebox' (libcachebox.so: cannot open shared object file: No such file or directory)"},{"fix":"Use a cache implementation with an eviction policy (e.g., `LRUCache`, `FIFOCache`, `TTLCache`) if you want the cache to automatically discard old items when `maxsize` is reached. If you intend for the cache to have no size limit, set `maxsize=0` during initialization, or simply use a standard Python `dict`.","cause":"This error occurs when using a basic `Cache` (or similar non-evicting cache) that has a `maxsize` defined, and you attempt to insert more items than its capacity. The default `Cache` implementation does not have an eviction policy.","error":"cachebox.OverflowError: The cache has reached the bound."}]}