# cachetiny

A tiny, dependency‑free, in‑memory caching decorator for Python with TTL
support and optional logging.

`cachetiny` is designed to be extremely small, easy to understand, and
useful for scripts, CLIs, APIs, and lightweight applications that need
fast caching without external services or disk storage.

------------------------------------------------------------------------

# Features

• Decorator-based API\
• In-memory cache (no files written to disk)\
• Configurable TTL (time-to-live)\
• Optional logging for cache hits vs computations\
• Thread-safe implementation\
• Zero dependencies\
• Extremely small and fast

------------------------------------------------------------------------

# Quick Example

``` python
import time
from cachetiny import cachetiny


@cachetiny(ttl=5, log=True)
def slow_add(a, b):
    print("Doing expensive work...")
    time.sleep(2)
    return a + b


print(slow_add(1, 2))
print(slow_add(1, 2))
print(slow_add(1, 2))

time.sleep(6)

print(slow_add(1, 2))
```

Example output:

    [cachetiny] COMPUTING -> slow_add(1, 2){}
    Doing expensive work...
    3

    [cachetiny] USING CACHE -> slow_add(1, 2){}
    3

    [cachetiny] USING CACHE -> slow_add(1, 2){}
    3

    [cachetiny] COMPUTING -> slow_add(1, 2){}
    Doing expensive work...
    3

------------------------------------------------------------------------

# API

## Decorator

    @cachetiny(ttl=60, log=False)

### Parameters

  Parameter   Type   Description
  ----------- ------ ------------------------------------------------
  ttl         int    Time in seconds before cache expires
  log         bool   Print when retrieving cache or computing value

------------------------------------------------------------------------

# Logging

When logging is enabled:

    @cachetiny(ttl=30, log=True)

You will see messages indicating whether the value was retrieved from
cache or computed again.

Example:

    [cachetiny] USING CACHE -> fetch_data(123){}
    [cachetiny] COMPUTING -> fetch_data(456){}

------------------------------------------------------------------------

# Important Behavior

### Cache is stored in memory

`cachetiny` does NOT write anything to disk.

This means:

✔ Extremely fast lookups\
✔ No file management\
✔ No external dependencies

But also:

⚠ Cache is cleared when the Python process exits.

------------------------------------------------------------------------

# Thread Safety

`cachetiny` uses a thread lock internally to protect the cache
dictionary.

This ensures safe behavior when multiple threads access cached
functions.

------------------------------------------------------------------------