Metadata-Version: 2.4
Name: pg-cache-storage
Version: 1.0.2
Summary: PostgreSQL cache storage for botasaurus.
Home-page: https://github.com/omkarcloud/botasaurus
Author: Chetan Jain
Author-email: 53407137+Chetan11-dev@users.noreply.github.com
License: MIT
Keywords: postgresql,pg-cache-storage,cache,botasaurus,psycopg3
Classifier: Development Status :: 5 - Production/Stable
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: psycopg[binary]
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# pg-cache-storage

PostgreSQL cache storage backend for botasaurus.

## Installation

```bash
pip install pg-cache-storage
```

## Usage

### With decorators like `@task`, `@request`, `@browser`

```python
from pg_cache_storage import PostgresCacheStorage
from botasaurus.task import task
from datetime import timedelta

# Create storage instance
pg_storage = PostgresCacheStorage(
    host="localhost",
    port=5432,
    username="postgres",
    password="postgres",
    db_name="cache"
)

@task(cache=True, expires_in=timedelta(days=1), cache_storage=pg_storage)
def my_scraper(data):
    # scraping logic
    return result
```

### With `@cache` decorator

```python
from pg_cache_storage import PostgresCacheStorage
from botasaurus.decorator_helpers import cache
from datetime import timedelta

# Create storage instance
pg_storage = PostgresCacheStorage(
    host="localhost",
    port=5432,
    username="postgres",
    password="postgres",
    db_name="cache"
)

# Use the decorator
@cache(expires_in=timedelta(days=1), cache_storage=pg_storage)
def my_function(data):
    # time-consuming operation
    return result
```


## API

### PostgresCacheStorage

```python
PostgresCacheStorage(
    host: str = 'localhost',
    port: int = 5432,
    username: str = 'postgres',
    password: str = 'postgres',
    db_name: str = 'cache',
    table_name: str = 'botasaurus_cache'
)
```

#### Methods

- `get(func_name, key_data, expires_in=None)` - Get cached value. Returns `{"data": value}` or `None`
- `put(func_name, key_data, data)` - Store value in cache
- `delete(func_name, key_data)` - Delete cached value

## License

MIT


