semvec/pypi-packages huggingface dataset:
cacheia-decorators 1.0.0.post3
Decorates for Cacheia library that allows invalidation and other shenanigans
Requires Python: >=3.12
Keywords: cache, decorator, method

# Cacheia Decorators

Exposes decorators that can be used along FastAPI and plain functions to cache responses using cacheia machinery.

## Installation

Install decorators with "schemas" optional and "local" and "remote" cache support:

```bash
pip install -e ./decorators[schemas,local,remote]
```

## Code

There are these decorators avaialble:

-   `local.cache`: which can be used on plain functions to cache values using a local cache or cacheia_client.
-   `remote.cache`: which can be used to cache values on a remote instance of cacheia (i.e. cacheia_api service).

## Usage

```python
from cacheia_decorators.local import cache as local_cache
from cacheia_decorators.remote import cache as remote_cache


@local_cache(key_builder=lambda i: str(i == 0), settings={})
def function_a():
    return "Hello World"

@remote_cache(key_builder=lambda i: str(i == 0), url="http://localhost:5000/")
def function_b():
    return "Hello World"
```
cacheia-api 1.0.0.post3
FastAPI based API for cache service that allows invalidation and other shenanigans
Requires Python: >=3.12
Keywords: api, cache, fastapi, middleware

# Cacheia API

This module contains the API for the Cacheia project. It exposes a HTTP interface to interact with all cacheia functionalities.

## Installation

Install core with "core" optional to download core dependency:

```bash
pip install -e ./api[core]
```

## API Endpoints

-   <span style="color:green">**POST**</span> `/cache/`: receives the body parameter `instance: CachedValue` and creates a new cache instance in the configured backend.
-   <span style="color:blue">**GET**</span> `/cache/`: receives the optional params `group: str, expires_range: tuple[float, float], creation_range: tuple[datetime, datetime]` and gets all cached values that match the filters.
-   <span style="color:blue">**GET**</span> `/cache/{key}/`: receives the params `key: str` and gets the cached value for the given key.
-   <span style="color:orange">**DELETE**</span> `/cache/`: receives the optional params `group: str, expires_range: tuple[float, float], creation_range: tuple[datetime, datetime]` and flushes all cached values that matched the criteria.
-   <span style="color:orange">**DELETE**</span> `/cache/{key}/`: receives the param `key: str` and flushes a specific key, removing its register in application cache.
-   <span style="color:orange">**DELETE**</span> `/cache/$clear/`: receives no params and flushes all cached values in the application cache.

## Docs

Run the code locally and check-out:

-   [Iterative](http://localhost:5000/docs): for an iterative experience
-   [Redoc](http://localhost:5000/redoc): for a more detailed view

## Running the API

To run the API it is only necessary to install the `cacheia_api` (api folder) and `cacheia` (core folder) packages and run the command:

`python -m cacheia_api`

It will run a local server with reload and one worker configured by default.
cacheia 1.0.0.post3
Cache library that allows invalidation and other shenanigans
Requires Python: >=3.12
Keywords: cache, core, lib

# Cacheia

Cacheia has all the core functionality for the "cacheia" package. It exposes a simple interface for multiple cache providers with added features like cache invalidation and cache expiration.

## Installation

Install core with "schemas" optional to download schemas dependency:

```bash
pip install -e ./core[schemas]
```

## Code

Cacheia mainly exposes one interface to interact with all backends and some custom exceptions:

-   Cacheia: The main interface to interact with all backends.
-   InvalidSettings: Exception raised when an invalid settings class type is passed to `Cacheia.setup` method.
-   KeyAlreadyExists: Exception raised when a key already exists in the cache and the user tries to set it again.
-   decorator: Module that exposes a decorator to cache function calls.

## Examples

To create a new cache:

```python
from cacheia import Cacheia
from cacheia_schemas import CachedValue


Cacheia.setup()
cache = Cacheia.get()
instance = CachedValue(key="key", value="value")
cache.cache(instance=instance)
```

---

To get all cached values:

```python
from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()
for value in cache.get():
    print(value)
```

---

To get a value from the cache:

```python
from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()
cached_value = cache.get_key("key")
print(cached_value)
```

---

To flush all values:

```python
from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()
result = cache.flush()
print(result.deleted_count)
```

---

To flush some values:

```python
from datetime import datetime
from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()

now = datetime.now().timestamp()
result = cache.flush(expires_range=(now - 100, now + 100))
print(result.deleted_count)
```

---

To flush a single key:

```python
from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()

result = cache.flush_key(key="key")
print(result.deleted_count)
```