{
  "name": "cache_get",
  "title": "Retrieve Cached Computation",
  "category": "Caching",
  "slug": "cache-get",
  "description": "Retrieve a previously cached computation result. Works with cache_write()\nand get_or_cache() to provide fast access to expensive computations.\n",
  "usage": "cache_get(name, default = NULL)",
  "params": [
    {
      "name": "name",
      "type": "character",
      "required": true,
      "description": "Name of the cached item to retrieve"
    },
    {
      "name": "default",
      "type": "any",
      "default": {},
      "description": "Value to return if cache miss or expired"
    }
  ],
  "returns": "The cached object if found and valid, otherwise the default value.\nReturns NULL if cache miss and no default specified.\n",
  "details": "cache_get() is part of Framework's caching system for expensive computations:\n\n**How it works:**\n- Looks up cache entry in framework.db\n- Checks if cache is expired (if expiration set)\n- Verifies cache file integrity via hash\n- Loads and returns cached object\n- Updates last_read_at timestamp\n\n**Cache expiration:**\n- Respects expire_at timestamp from cache_write()\n- Returns default if expired\n- Use cache = Inf for never-expiring cache\n\n**Performance:**\n- Fast lookup via SQLite index\n- Hash verification prevents corruption\n- Updates access time for cache management\n\n**Common patterns:**\n- Check cache first, compute if missing\n- Use get_or_cache() for automatic pattern\n- Pair with cache_delete() for invalidation\n",
  "examples": [
    {
      "code": "# Try to get cached result\nresult <- cache_get(\"expensive_analysis\")\nif (is.null(result)) {\n  result <- expensive_function()\n  cache_write(\"expensive_analysis\", result)\n}\n",
      "description": "Manual cache check pattern"
    },
    {
      "code": "# Provide default value for cache miss\nresult <- cache_get(\"analysis\", default = data.frame())\n",
      "description": "Cache with fallback default"
    },
    {
      "code": "# Better: use get_or_cache() for automatic pattern\nresult <- get_or_cache(\"expensive_analysis\", {\n  expensive_function()\n})\n",
      "description": "Recommended approach using get_or_cache()"
    },
    {
      "code": "# Check what's in cache\ncache_list()  # See all cached items\ncache_get(\"my_cache\")  # Retrieve specific item\n",
      "description": "Exploring cached items"
    }
  ],
  "related": ["cache_write", "cache_delete", "get_or_cache", "cache_list"],
  "see_also": [
    {
      "name": "cache_write",
      "description": "Store computation result in cache"
    },
    {
      "name": "get_or_cache",
      "description": "Get cached value or compute and cache"
    },
    {
      "name": "cache_delete",
      "description": "Remove item from cache"
    }
  ],
  "tags": ["caching", "performance", "memoization"],
  "notes": ["Cache files stored in directory specified by config(\"cache\")", "Default cache directory is data/cached/", "Use cache_list() to see all cached items and expiration", "Cache integrity verified via MD5 hash"]
}
