developer #4
@ -17,13 +17,18 @@ export async function fetchPrefeituraInfo(dominio: string): Promise<PrefeituraIn
|
||||
if (!dominio) return null
|
||||
|
||||
const cacheKey = `prefeitura:${dominio}`
|
||||
const cached = await useRedis().get(cacheKey)
|
||||
if (cached) {
|
||||
try {
|
||||
return JSON.parse(cached) as PrefeituraInfo
|
||||
} catch {
|
||||
// cache corrompido — segue para refetch
|
||||
let redisAvailable = true
|
||||
try {
|
||||
const cached = await useRedis().get(cacheKey)
|
||||
if (cached) {
|
||||
try {
|
||||
return JSON.parse(cached) as PrefeituraInfo
|
||||
} catch {
|
||||
// cache corrompido — segue para refetch
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
redisAvailable = false
|
||||
}
|
||||
|
||||
const cfg = useRuntimeConfig()
|
||||
@ -35,7 +40,9 @@ export async function fetchPrefeituraInfo(dominio: string): Promise<PrefeituraIn
|
||||
const info = res?.data
|
||||
if (!info?.codigoMunicipio) return null
|
||||
|
||||
await useRedis().set(cacheKey, JSON.stringify(info), 'EX', CACHE_TTL_SECONDS)
|
||||
if (redisAvailable) {
|
||||
await useRedis().set(cacheKey, JSON.stringify(info), 'EX', CACHE_TTL_SECONDS).catch(() => {})
|
||||
}
|
||||
return info
|
||||
} catch (err) {
|
||||
console.error(`[prefeitura] lookup falhou para '${dominio}':`, (err as Error).message)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user