MCPcopy Index your code
hub / github.com/awolverp/cachebox

github.com/awolverp/cachebox @v6.1.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v6.1.2 ↗ · + Follow
1,341 symbols 5,066 edges 53 files 165 documented · 12% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Cachebox

The fastest caching Python library written in Rust

Documentation | Releases | Benchmarks | Issues

License Downloads


[!WARNING]\ The new version v6 has incompatibilities with v5. For more info see Migration Guide.

What does it do?

You can easily perform powerful caching operations in Python as fast as possible. This can make your application a lot faster and it can be a good choice in complex applications. Ideal for optimizing large-scale applications with efficient, low-overhead caching.

Key Features: - 🚀 Extremely fast (10-50x faster than other caching libraries - benchmarks) - 📊 Minimal memory footprint - 🔥 Full-featured and user-friendly - 🧶 Completely thread-safe - 🔧 Tested and correct - [R] written in Rust for maximum performance - 🤝 Compatible with Python 3.10+ (PyPy and CPython) - 📦 Supports 7 advanced caching algorithms

When do I need caching?

  • 📈 Frequent Data Access \ If you need to access the same data multiple times, caching can help reduce the number of database queries or API calls, improving performance.

  • 💎 Expensive Operations \ If you have operations that are computationally expensive, caching can help reduce the number of times these operations need to be performed.

  • 🚗 High Traffic Scenarios \ If your application handles high traffic, caching can help reduce the load on your server by reducing the number of requests that need to be processed.

  • #️⃣ Web Page Rendering \ If you are rendering web pages, caching can help reduce the time it takes to generate the page by caching the results of expensive rendering operations. Caching HTML pages can speed up the delivery of static content.

  • 🚧 Rate Limiting \ If you have a rate limiting system in place, caching can help reduce the number of requests that need to be processed by the rate limiter. Also, caching can help you to manage rate limits imposed by third-party APIs by reducing the number of requests sent.

  • 🤖 Machine Learning Models \ If your application frequently makes predictions using the same input data, caching the results can save computation time.

Why cachebox?

  • ⚡ Rust \ It uses the Rust language for high-performance.

  • 🧮 SwissTable \ It uses Google's high-performance SwissTable hash map. Thanks to hashbrown.

  • ✨ Low memory usage \ It has very low memory usage.

  • ⭐ Zero Dependency \ As we said, cachebox is written in Rust so you don't have to install any other dependecies.

  • 🧶 Thread safe \ It's completely thread-safe and uses Rust mutex to prevent problems.

  • 👌 Easy To Use \ You only need to import it and choose a cache implementation to use.

  • 🚫 Avoids Cache Stampede \ It avoids cache stampede by using a distributed lock system.

Installation

cachebox is installable via pip:

pip3 install -U cachebox

Examples

The simplest example of cachebox could look like this:

import cachebox

@cachebox.cached(cachebox.FIFOCache(maxsize=128))
def factorial(number: int) -> int:
    fact = 1
    for num in range(2, number + 1):
        fact *= num
    return fact

assert factorial(5) == 125

# coroutines are also supported
@cachebox.cached(cachebox.LRUCache(maxsize=128))
async def make_request(method: str, url: str) -> dict:
    response = await client.request(method, url)
    return response.json()

Unlike functools.lru_cache and other caching libraries, cachebox can copy dict, list, and set objects.

@cachebox.cached(cachebox.LRUCache(maxsize=128))
def make_dict(name: str, age: int) -> dict:
   return {"name": name, "age": age}
>
d = make_dict("cachebox", 10)
assert d == {"name": "cachebox", "age": 10}
d["new-key"] = "new-value"

d2 = make_dict("cachebox", 10)
# `d2` will be `{"name": "cachebox", "age": 10, "new-key": "new-value"}` if you use other libraries
assert d2 == {"name": "cachebox", "age": 10}

You can use cache alghoritms without the cached decorator -- just import the cache alghoritm you want and use it like a dictionary.

from cachebox import FIFOCache

cache = FIFOCache(maxsize=128)
cache["key"] = "value"
assert cache["key"] == "value"

# You can also use `cache.get(key, default)`
assert cache.get("key") == "value"

Learn more

Read the documentation for full information and learn more: Documentation

License

This repository is licensed under the MIT License

Extension points exported contracts — how you extend this code

OccupiedExt (Interface)
Guard for an *occupied* slot. [7 implementers]
src/policies/traits.rs
Receive (Interface)
Accepts a single raw owned pointer from a finished child builder. [5 implementers]
src/internal/pickle.rs
RawTableClone (Interface)
Specialization of `clone_from` for `Copy` types [1 implementers]
src/hashbrown/raw.rs
VacantExt (Interface)
Guard for a *vacant* slot. [7 implementers]
src/policies/traits.rs
Builder (Interface)
(no doc) [5 implementers]
src/internal/pickle.rs
TagSliceExt (Interface)
Extension trait for slices of tags. [1 implementers]
src/hashbrown/control/tag.rs
PolicyExt (Interface)
(no doc) [7 implementers]
src/policies/traits.rs
SizedTypeProperties (Interface)
(no doc) [1 implementers]
src/hashbrown/raw.rs

Core symbols most depended-on inside this repo

insert
called by 188
src/hashbrown/raw.rs
policy
called by 182
src/policies/wrapped.rs
shared
called by 152
src/policies/wrapped.rs
create_cache
called by 110
tests/mixins.py
as_ptr
called by 89
src/hashbrown/raw.rs
len
called by 70
src/hashbrown/raw.rs
generation_version
called by 70
src/policies/common.rs
clone_ref
called by 67
src/policies/common.rs

Shape

Method 1,118
Class 125
Function 75
Interface 10
Enum 7
Route 6

Languages

Rust64%
Python36%

Modules by API surface

tests/mixins.py164 symbols
tests/test_impls.py160 symbols
src/hashbrown/raw.rs141 symbols
tests/test_utils.py76 symbols
cachebox/utils.py50 symbols
src/pyclasses/ttlcache.rs47 symbols
src/pyclasses/vttlcache.rs44 symbols
src/pyclasses/lrucache.rs42 symbols
src/pyclasses/lfucache.rs42 symbols
src/pyclasses/fifocache.rs41 symbols
src/pyclasses/rrcache.rs40 symbols
src/pyclasses/cache.rs39 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add cachebox \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact