Skip to main content

PostgreSQL cache storage for botasaurus.

Project description

pg-cache-storage

PostgreSQL cache storage backend for botasaurus.

Installation

pip install pg-cache-storage

Usage

With decorators like @task, @request, @browser

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

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pg_cache_storage-1.0.2.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file pg_cache_storage-1.0.2.tar.gz.

File metadata

  • Download URL: pg_cache_storage-1.0.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pg_cache_storage-1.0.2.tar.gz
Algorithm Hash digest
SHA256 41ad1512d1738bced93162f723268aa50ce1dbfff8b00c6a9ed43f4c082147b2
MD5 a0698b02b314e76a2cf04e99c5a59c05
BLAKE2b-256 fb91a55959976e3b131e2fc3ff457f237f71d856ad3b01240d10f1c0c7c1fd65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page