caching-utilities

Guide for using caching utilities in speedy_utils, including memory, disk, and hybrid caching strategies for sync and async functions.

16 stars

Best use case

caching-utilities is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Guide for using caching utilities in speedy_utils, including memory, disk, and hybrid caching strategies for sync and async functions.

Teams using caching-utilities should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/caching-utilities/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/design/caching-utilities/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/caching-utilities/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How caching-utilities Compares

Feature / Agentcaching-utilitiesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Guide for using caching utilities in speedy_utils, including memory, disk, and hybrid caching strategies for sync and async functions.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Caching Utilities Guide

This skill provides comprehensive guidance for using the caching utilities in `speedy_utils`.

## When to Use This Skill

Use this skill when you need to:
- Optimize performance by caching expensive function calls.
- Persist results across program runs using disk caching.
- Use memory caching for fast access within a single run.
- Handle caching for both synchronous and asynchronous functions.
- Use `imemoize` for persistent caching in interactive environments like Jupyter notebooks.

## Prerequisites

- `speedy_utils` installed in your environment.

## Core Capabilities

### Universal Memoization (`@memoize`)
- Supports `memory`, `disk`, and `both` (hybrid) caching backends.
- Works with both `sync` and `async` functions.
- Configurable LRU cache size for memory caching.
- Custom key generation strategies.

### Interactive Memoization (`@imemoize`)
- Designed for Jupyter notebooks and interactive sessions.
- Persists cache across module reloads (`%load`).
- Uses global memory cache.

### Object Identification (`identify`)
- Generates stable, content-based identifiers for arbitrary Python objects.
- Handles complex types like DataFrames, Pydantic models, and nested structures.

## Usage Examples

### Example 1: Basic Hybrid Caching
Cache results in both memory and disk.

```python
from speedy_utils import memoize
import time

@memoize(cache_type='both', size=128)
def expensive_func(x: int):
    time.sleep(1)
    return x * x
```

### Example 2: Async Disk Caching
Cache results of an async function to disk.

```python
from speedy_utils import memoize
import asyncio

@memoize(cache_type='disk', cache_dir='./my_cache')
async def fetch_data(url: str):
    # simulate network call
    await asyncio.sleep(1)
    return {"data": "content"}
```

### Example 3: Custom Key Function
Use a custom key function for complex arguments.

```python
from speedy_utils import memoize

def get_user_id(user):
    return user.id

@memoize(key=get_user_id)
def process_user(user):
    # ...
    pass
```

### Example 4: Interactive Caching (Notebooks)
Use `@imemoize` to keep cache even if you reload the cell/module.

```python
from speedy_utils import imemoize

@imemoize
def notebook_func(data):
    # ...
    return result
```

## Guidelines

1.  **Choose the Right Backend**:
    - Use `memory` for small, fast results needed frequently in one session.
    - Use `disk` for large results or to persist across runs.
    - Use `both` (default) for the best of both worlds.

2.  **Key Stability**:
    - Ensure arguments are stable (e.g., avoid using objects with changing internal state as keys unless you provide a custom `key` function).
    - `identify` handles most common types, but be careful with custom classes without `__repr__` or stable serialization.

3.  **Cache Directory**:
    - Default disk cache is `~/.cache/speedy_cache`.
    - Override `cache_dir` for project-specific caching.

4.  **Async Support**:
    - The decorators automatically detect `async` functions and handle `await` correctly.
    - Do not mix sync/async usage without proper `await`.

## Common Patterns

### Pattern: Ignoring `self`
By default, `ignore_self=True` is set. This means methods on different instances of the same class will share cache if other arguments are the same. Set `ignore_self=False` if the instance state matters.

```python
class Processor:
    def __init__(self, multiplier):
        self.multiplier = multiplier

    @memoize(ignore_self=False)
    def compute(self, x):
        return x * self.multiplier
```

## Limitations

- **Pickle Compatibility**: Disk caching relies on `pickle` (or JSON). Ensure return values are serializable.
- **Cache Invalidation**: There is no automatic TTL (Time To Live) or expiration. You must manually clear cache files if data becomes stale.

Related Skills

pdf-utilities

16
from diegosouzapw/awesome-omni-skill

Read, extract, edit, and manipulate PDF documents including table extraction, page manipulation, fillable forms, and comments.

llm-caching

16
from diegosouzapw/awesome-omni-skill

Optimize LLM costs and latency through KV caching and prompt caching. Use when (1) structuring prompts for cache hits, (2) configuring API cache_control for Anthropic/Cohere/OpenAI/Gemini, (3) setting up self-hosted inference with vLLM/SGLang/Ollama, (4) building agentic workflows with prefix reuse, (5) designing batch processing pipelines, or (6) understanding cache pricing and tradeoffs.

gitlab-ci-artifacts-caching

16
from diegosouzapw/awesome-omni-skill

Use when configuring artifacts for inter-job data passing or caching for faster builds. Covers cache strategies and artifact management.

apollo-caching-strategies

16
from diegosouzapw/awesome-omni-skill

Use when implementing Apollo caching strategies including cache policies, optimistic UI, cache updates, and normalization.

prompt-caching

16
from diegosouzapw/awesome-omni-skill

Caching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation) Use when: prompt caching, cache prompt, response cache, cag, cache augmented.

bgo

10
from diegosouzapw/awesome-omni-skill

Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.

Coding & Development

Empirical Validation

16
from diegosouzapw/awesome-omni-skill

Requires proof before marking work complete — no "trust me, it works"

dubstep

16
from diegosouzapw/awesome-omni-skill

Dubstep composition specialist - genre knowledge, sound design, and production patterns for LMMS

dotnet-ui-testing-core

16
from diegosouzapw/awesome-omni-skill

Tests UI across frameworks. Page objects, test selectors, async waits, accessibility.

dev-server-sandbox

16
from diegosouzapw/awesome-omni-skill

Run multiple isolated mux dev-server instances (temp MUX_ROOT + free ports)

detect-design

16
from diegosouzapw/awesome-omni-skill

Design system detection with drift findings and evidence blocks. Use when auditing design system consistency.

design_responsive

16
from diegosouzapw/awesome-omni-skill

Breakpoints, fluid typography, container queries ve modern CSS features.