Metadata-Version: 2.1
Name: cacheia
Version: 1.0.0.post3
Summary: Cache library that allows invalidation and other shenanigans
Author-email: TeiaLabs <contato@teialabs.com>
Keywords: cache,core,lib
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: pymongo<5,>=4
Requires-Dist: boto3~=1.34
Requires-Dist: redis<6,>=5
Requires-Dist: pydantic<3,>=2
Requires-Dist: pydantic_settings<3,>=2
Provides-Extra: dev
Requires-Dist: black<25,>=24; extra == "dev"
Requires-Dist: isort<6,>=5; extra == "dev"
Requires-Dist: pytest<9,>=8; extra == "dev"
Provides-Extra: schemas
Requires-Dist: cacheia_schemas==1.0.0; extra == "schemas"

# 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)
```
