{"id":15494809,"url":"https://github.com/janbjorge/pgcachewatch","last_synced_at":"2026-03-04T21:02:52.784Z","repository":{"id":223205298,"uuid":"644768006","full_name":"janbjorge/PGCacheWatch","owner":"janbjorge","description":"A Python library for real-time PostgreSQL event-driven cache invalidation.","archived":false,"fork":false,"pushed_at":"2025-04-20T07:47:14.000Z","size":252,"stargazers_count":22,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-17T04:22:13.061Z","etag":null,"topics":["cache","event-driven","postgres","python310","python311","python312","web","webdevelopment"],"latest_commit_sha":null,"homepage":"https://pgcachewatch.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/janbjorge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-24T08:07:02.000Z","updated_at":"2025-04-07T22:07:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"ac9a71e7-c566-406d-99c9-36c80f4e8242","html_url":"https://github.com/janbjorge/PGCacheWatch","commit_stats":{"total_commits":67,"total_committers":1,"mean_commits":67.0,"dds":0.0,"last_synced_commit":"9f7e3979ac81b2c55e846ed56638862d6e68743c"},"previous_names":["janbjorge/pgcachewatch"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/janbjorge/PGCacheWatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janbjorge%2FPGCacheWatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janbjorge%2FPGCacheWatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janbjorge%2FPGCacheWatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janbjorge%2FPGCacheWatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janbjorge","download_url":"https://codeload.github.com/janbjorge/PGCacheWatch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janbjorge%2FPGCacheWatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30092877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T20:42:30.420Z","status":"ssl_error","status_checked_at":"2026-03-04T20:42:30.057Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","event-driven","postgres","python310","python311","python312","web","webdevelopment"],"created_at":"2024-10-02T08:15:19.527Z","updated_at":"2026-03-04T21:02:50.218Z","avatar_url":"https://github.com/janbjorge.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"##  🚀 PGCacheWatch - Supercharge Your Caching Strategy 🚀\n[![CI](https://github.com/janbjorge/PGCacheWatch/actions/workflows/ci.yml/badge.svg)](https://github.com/janbjorge/PGCacheWatch/actions/workflows/ci.yml?query=branch%3Amain)\n[![pypi](https://img.shields.io/pypi/v/PGCacheWatch.svg)](https://pypi.python.org/pypi/PGCacheWatch)\n[![downloads](https://static.pepy.tech/badge/PGCacheWatch/month)](https://pepy.tech/project/PGCacheWatch)\n[![versions](https://img.shields.io/pypi/pyversions/PGCacheWatch.svg)](https://github.com/janbjorge/PGCacheWatch)\n\n---\n📚 **Documentation**: [Explore the Docs 📖](https://pgcachewatch.readthedocs.io/en/latest/)\n\n🔍 **Source Code**: [View on GitHub 💾](https://github.com/janbjorge/PGCacheWatch/)\n\n---\nPGCacheWatch is the a Python library designed to propel your applications into a new realm of efficiency with real-time PostgreSQL event notifications for cache invalidation. Wave goodbye to stale data and hello to seamless cache management, bolstered performance powered by the robust backbone of PostgreSQL.\n\n## Example with FastAPI\nPGCacheWatch integrates with FastAPI, empowering you to keep your application's data fresh and consistent by dynamically invalidating cache in line with database updates.\n\n```python\nimport contextlib\nimport typing\n\nimport asyncpg\nfrom fastapi import FastAPI\nfrom pgcachewatch import decorators, listeners, models, strategies\n\n# Initialize a PGEventQueue listener to listen for database events.\nlistener = listeners.PGEventQueue()\n\n@contextlib.asynccontextmanager\nasync def app_setup_teardown(_: FastAPI) -\u003e typing.AsyncGenerator[None, None]:\n    \"\"\"\n    Asynchronous context manager for FastAPI app setup and teardown.\n\n    This context manager is used to establish and close the database connection\n    at the start and end of the FastAPI application lifecycle, respectively.\n    \"\"\"\n    # Establish a database connection using asyncpg.\n    conn = await asyncpg.connect()\n    # Connect the listener to the database using the specified channel.\n    await listener.connect(conn)\n\n    try:\n        yield\n    finally:\n        await conn.close()  # Ensure the database connection is closed on app teardown.\n\n# Create an instance of FastAPI, specifying the app setup and teardown actions.\nAPP = FastAPI(lifespan=app_setup_teardown)\n\n# Decorate the cached_query function with cache invalidation logic.\n@decorators.cache(\n    strategy=strategies.Greedy(\n        listener=listener,\n        # Invalidate the cache only for 'update' operations on the database.\n        predicate=lambda x: x.operation == \"update\",\n    )\n)\nasync def cached_query(user_id: int) -\u003e dict[str, str]:\n    \"\"\"\n    Simulates a database query that benefits from cache invalidation.\n\n    This function is decorated to use PGCacheWatch's cache invalidation, ensuring\n    that the data returned is up-to-date following any relevant 'update' operations\n    on the database.\n    \"\"\"\n    # Return a mock data response.\n    return {\"data\": \"query result\"}\n\n# Define a FastAPI route to fetch data, utilizing the cached_query function.\n@APP.get(\"/data\")\nasync def get_data(user_id: int) -\u003e dict:\n    \"\"\"\n    This endpoint uses the cached_query function to return data, demonstrating\n    how cache invalidation can be integrated into a web application route.\n    \"\"\"\n    # Fetch and return the data using the cached query function.\n    return await cached_query(user_id)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanbjorge%2Fpgcachewatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanbjorge%2Fpgcachewatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanbjorge%2Fpgcachewatch/lists"}