forked from cartsnitch/cartsnitch
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a53daddb9a | |||
| 3351d74058 |
@@ -47,30 +47,5 @@ class CacheClient:
|
|||||||
return
|
return
|
||||||
await self._client.delete(key)
|
await self._client.delete(key)
|
||||||
|
|
||||||
async def invalidate_price_cache(self, product_id: str) -> None:
|
|
||||||
"""Invalidate all price-related cache entries for a product."""
|
|
||||||
if not self._client:
|
|
||||||
return
|
|
||||||
pattern = f"price:*:{product_id}"
|
|
||||||
await self._delete_pattern(pattern)
|
|
||||||
|
|
||||||
async def invalidate_product_cache(self, product_id: str) -> None:
|
|
||||||
"""Invalidate the product detail cache entry."""
|
|
||||||
if not self._client:
|
|
||||||
return
|
|
||||||
await self._client.delete(f"product:{product_id}")
|
|
||||||
|
|
||||||
async def _delete_pattern(self, pattern: str) -> None:
|
|
||||||
"""Delete all keys matching a pattern using SCAN."""
|
|
||||||
if not self._client:
|
|
||||||
return
|
|
||||||
cursor = 0
|
|
||||||
while True:
|
|
||||||
cursor, keys = await self._client.scan(cursor=cursor, match=pattern, count=100)
|
|
||||||
if keys:
|
|
||||||
await self._client.delete(*keys)
|
|
||||||
if cursor == 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
cache_client = CacheClient()
|
cache_client = CacheClient()
|
||||||
|
|||||||
+12
-6
@@ -4,17 +4,23 @@ import pg from "pg";
|
|||||||
|
|
||||||
const { Pool } = pg;
|
const { Pool } = pg;
|
||||||
|
|
||||||
const pool = new Pool({
|
|
||||||
connectionString:
|
|
||||||
process.env.DATABASE_URL ??
|
|
||||||
"postgresql://cartsnitch:cartsnitch@localhost:5432/cartsnitch",
|
|
||||||
});
|
|
||||||
|
|
||||||
const secret = process.env.BETTER_AUTH_SECRET;
|
const secret = process.env.BETTER_AUTH_SECRET;
|
||||||
if (!secret) {
|
if (!secret) {
|
||||||
throw new Error("BETTER_AUTH_SECRET environment variable is required");
|
throw new Error("BETTER_AUTH_SECRET environment variable is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const databaseUrl = process.env.DATABASE_URL;
|
||||||
|
if (!databaseUrl) {
|
||||||
|
console.warn(
|
||||||
|
"WARNING: DATABASE_URL is not set — using default localhost connection. " +
|
||||||
|
"Set DATABASE_URL for production deployments."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
connectionString: databaseUrl ?? "postgresql://cartsnitch:cartsnitch@localhost:5432/cartsnitch",
|
||||||
|
});
|
||||||
|
|
||||||
export const auth = betterAuth({
|
export const auth = betterAuth({
|
||||||
database: pool,
|
database: pool,
|
||||||
basePath: "/auth",
|
basePath: "/auth",
|
||||||
|
|||||||
Generated
+3
-3
@@ -9805,9 +9805,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/vite": {
|
"node_modules/vite": {
|
||||||
"version": "6.4.1",
|
"version": "6.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.2.tgz",
|
||||||
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
|
"integrity": "sha512-2N/55r4JDJ4gdrCvGgINMy+HH3iRpNIz8K6SFwVsA+JbQScLiC+clmAxBgwiSPgcG9U15QmvqCGWzMbqda5zGQ==",
|
||||||
"devOptional": true,
|
"devOptional": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user