caching-optimizer

Cache expensive computations and I/O operations in Streamlit apps with @st.cache_data and @st.cache_resource.

2|2|Updated Nov 4, 2025
One-click install
npx skills add https://github.com/gizix/cc_projects --skill caching-optimizer-gizix
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: caching-optimizer
Source: https://github.com/gizix/cc_projects/tree/main/streamlit-template/.claude/skills/caching-optimizer
Command: npx skills add https://github.com/gizix/cc_projects --skill caching-optimizer-gizix

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides practical caching strategies for Streamlit apps to reduce recomputation and improve user experience.

Core Features & Use Cases

  • Data Caching: Cache heavy data loads and transformations.
  • Resource Caching: Cache external connections or models.
  • Cache Invalidation & Monitoring: Clear or manage caches to stay fresh.

Quick Start

Wrap an expensive function with @st.cache_data and demonstrate cache invalidation when inputs change.

Frequently Asked Questions about caching-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I speed up my Streamlit app by caching expensive computations?▼

Caching reduces latency in Streamlit applications by storing results of expensive operations. Use @st.cache_data for data loads and transformations, and @st.cache_resource for external connections or ML models. Wrap the function once, and Streamlit automatically reuses cached results on repeated calls with identical inputs.

What's the difference between @st.cache_data and @st.cache_resource?▼

@st.cache_data caches serializable outputs like dataframes and API responses; @st.cache_resource caches unserializable objects like database connections and loaded models. Use cache_data for computations and transformations; use cache_resource for stateful resources that persist across reruns.

How do I invalidate or clear cached data when inputs change?▼

Cache invalidation happens automatically when function parameters differ, ensuring fresh results for new inputs. Implement TTL-based expiration to refresh stale data, use manual cache clearing for on-demand updates, or apply conditional caching logic to balance freshness and performance based on your use case.

Can I cache functions with complex data types or custom objects?▼

Yes. Streamlit's caching handles most built-in types automatically. For complex or custom types, implement custom hash handling to tell the cache how to recognize identical inputs, avoiding unnecessary recomputation while maintaining correctness.

When should I set cache size limits or TTL values?▼

Set size limits when memory is constrained or data is frequently updated; configure TTL for real-time data sources where staleness matters. Without limits, caches grow unbounded; without TTL, old data persists indefinitely. Balance retention against freshness requirements for your analytics or preprocessing pipeline.

Does caching work for data loading and API responses in iterative analytics?▼

Yes. Caching is designed for repeated data loads, API calls, and preprocessing pipelines in iterative analytics workflows. Once cached, subsequent queries return results instantly, improving user experience during exploration without re-fetching or reprocessing.