feat: remove redis caching

This commit is contained in:
ayo 2026-06-24 10:43:57 +02:00
parent ff7b3a71b0
commit 9b9f6242b3

View file

@ -1,5 +1,4 @@
--- ---
import { createClient, type RedisJSON } from 'redis'
import { type ArticleData, extract } from '@extractus/article-extractor' import { type ArticleData, extract } from '@extractus/article-extractor'
import AddressBar from '../components/AddressBar.astro' import AddressBar from '../components/AddressBar.astro'
@ -8,11 +7,6 @@ import App from '../layouts/App.astro'
import Library from '../components/Library.astro' import Library from '../components/Library.astro'
import Footer from '../components/Footer.astro' import Footer from '../components/Footer.astro'
// Initialize Redis client
const client = createClient()
client.on('error', (err) => console.error('Redis Client Error', err))
await client.connect()
// Disable prerendering for dynamic content // Disable prerendering for dynamic content
export const prerender = false export const prerender = false
@ -35,27 +29,10 @@ while (url?.startsWith(Astro.url.origin)) {
// Process article extraction only if a valid URL is provided // Process article extraction only if a valid URL is provided
if (url && url !== '/' && url !== '') { if (url && url !== '/' && url !== '') {
const cacheKey = 'cozy:url:' + url
try { try {
// Check if article exists in Redis cache // Fetch article from the web
const exists = await client.exists(cacheKey) article = await extract(url)
console.log('>>> Using fetched content', article?.url)
if (exists) {
// Retrieve cached article data
article = (await client.json.get(cacheKey)) as ArticleData
console.log('>>> Using cached content', article.url)
} else {
// Fetch article from the web
article = await extract(url)
console.log('>>> Using fetched content', article?.url)
if (article !== null && article.url) {
// Cache the fetched article in Redis
await client.json.set(cacheKey, '$', article as RedisJSON)
console.log('>>> Added to cache', article.url)
}
}
} catch (error) { } catch (error) {
// Log error and continue with null article // Log error and continue with null article
console.error('Error processing article:', error) console.error('Error processing article:', error)