Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] 缓存问题 #253

Open
PSGO opened this issue Sep 14, 2024 · 7 comments
Open

[Bug] 缓存问题 #253

PSGO opened this issue Sep 14, 2024 · 7 comments
Labels
bug Something isn't working PR welcome Good for new contributor

Comments

@PSGO
Copy link

PSGO commented Sep 14, 2024

编辑文章后,D1数据库中feed数据是正确的,但是文章展示是旧的,在设置中多次清除缓存依然是旧的,Ctrl f5依然是旧的,多次刷新会出现新旧交替的情况,没有固定规律

@PBK-B PBK-B added the bug Something isn't working label Sep 19, 2024
@OXeu
Copy link
Collaborator

OXeu commented Oct 11, 2024

看起来应该是 Cloudflare worker 复用的问题,通常半个小时后应该就会恢复正常

@PSGO
Copy link
Author

PSGO commented Oct 12, 2024

看起来应该是 Cloudflare worker 复用的问题,通常半个小时后应该就会恢复正常

好的,我重新部署再观察一下,谢谢回复

@panghaibin
Copy link
Contributor

panghaibin commented Nov 3, 2024

感觉把这里

const response = await fetch(new Request(this.cacheUrl))

改成

const response = await fetch(new Request(`${this.cacheUrl}?_t=${new Date().getTime()}`))

也许能缓解。不过缓存脏读没找到稳定复现的方法,没法验证是否能修复。 改了以后还是没修复,不是这个问题

@panghaibin
Copy link
Contributor

panghaibin commented Nov 9, 2024

你的文章是不是设置了别名?在设置了别名且通过别名访问文章的情况下,能复现缓存错乱

async function clearFeedCache(id: number, alias: string | null, newAlias: string | null) {
const cache = PublicCache()
await cache.deletePrefix('feeds_');
await cache.deletePrefix('search_');
await cache.delete(`feed_${id}`, false);
if (alias === newAlias) return;
if (alias)
await cache.delete(`feed_${alias}`, false);
if (newAlias)
await cache.delete(`feed_${newAlias}`, false);
}

@OXeu 这里的逻辑有点没看懂,仅当别名更改时才清除别名的缓存吗?

@OXeu
Copy link
Collaborator

OXeu commented Nov 9, 2024

你的文章是不是设置了别名?在设置了别名且通过别名访问文章的情况下,能复现缓存错乱

async function clearFeedCache(id: number, alias: string | null, newAlias: string | null) {
const cache = PublicCache()
await cache.deletePrefix('feeds_');
await cache.deletePrefix('search_');
await cache.delete(`feed_${id}`, false);
if (alias === newAlias) return;
if (alias)
await cache.delete(`feed_${alias}`, false);
if (newAlias)
await cache.delete(`feed_${newAlias}`, false);
}

@OXeu 这里的逻辑有点没看懂,仅当别名更改时才清除别名的缓存吗?

看起来确实是个判断的 bug

@panghaibin
Copy link
Contributor

有点疑惑typedi在CloudFlare Workers的生命周期是多少?按理说每次请求都应该会重新实例化CacheImpl才对,但从打的日志上看,有时这个请求只打了Cache hit的日志,没打Cache load的,应该每次请求都要触发load()才对吧?

@OXeu
Copy link
Collaborator

OXeu commented Nov 11, 2024

有点疑惑typedi在CloudFlare Workers的生命周期是多少?按理说每次请求都应该会重新实例化CacheImpl才对,但从打的日志上看,有时这个请求只打了Cache hit的日志,没打Cache load的,应该每次请求都要触发load()才对吧?

单个 worker 短期内是会处理多个请求的,并不是每个请求都创建一个新的

@OXeu OXeu added the PR welcome Good for new contributor label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR welcome Good for new contributor
Projects
None yet
Development

No branches or pull requests

4 participants