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

Improve cache context #23330

Merged
merged 12 commits into from Mar 8, 2023
Merged

Conversation

wolfogre
Copy link
Member

@wolfogre wolfogre commented Mar 6, 2023

Related to: #22294 #23186 #23054

Replace: #23218

Some discussion is in the comments of #23218.

Highlights:

  • Add Expiration for cache context. If a cache context has been used for more than 10s, the cache data will be ignored, and warning logs will be printed.
  • Add discard field to cacheContext, a cacheContext with discard true will drop all cached data and won't store any new one.
  • Introduce WithNoCacheContext, if one wants to run long-life tasks, but the parent context is a cache context, WithNoCacheContext(perentCtx) will discard the cache data, so it will be safe to keep the context for a long time.
  • It will be fine to treat an original context as a cache context, like GetContextData(context.Backgraud()), no warning logs will be printed.

Some cases about nesting:

When:

  • A, B or C means a cache context.
  • A, B or C means a discard cache context.
  • ctx means context.Backgrand()
  • A(ctx) means a cache context with ctx as the parent context.
  • B(A(ctx)) means a cache context with A(ctx) as the parent context.
  • With means WithCacheContext
  • WithNo means WithNoCacheContext

So:

  • With(ctx) -> A(ctx)
  • With(With(ctx)) -> A(ctx), not B(A(ctx))
  • With(With(With(ctx))) -> A(ctx), not C(B(A(ctx)))
  • WithNo(ctx) -> ctx, not A(ctx)
  • WithNo(With(ctx)) -> A(ctx)
  • WithNo(WithNo(With(ctx))) -> A(ctx), not B(A(ctx))
  • With(WithNo(With(ctx))) -> B(A(ctx))
  • WithNo(With(WithNo(With(ctx)))) -> B(A(ctx))
  • With(WithNo(With(WithNo(With(ctx))))) -> C(B(A(ctx)))

@wolfogre wolfogre added the type/enhancement An improvement of existing functionality label Mar 6, 2023
@wolfogre wolfogre added this to the 1.20.0 milestone Mar 6, 2023
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 6, 2023
@wxiaoguang
Copy link
Contributor

The description seems very valuable. Maybe the description could be put into code as package comment? If would help future developers when they are using the package.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 6, 2023
modules/cache/context.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 7, 2023
@wolfogre wolfogre added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 8, 2023
@jolheiser
Copy link
Member

🎺 🤖

@jolheiser jolheiser merged commit 1960ad5 into go-gitea:main Mar 8, 2023
@jolheiser jolheiser removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 8, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 9, 2023
* giteaofficial/main:
  Test renderReadmeFile (go-gitea#23185)
  [skip ci] Updated translations via Crowdin
  Set `X-Gitea-Debug` header once (go-gitea#23361)
  Improve cache context (go-gitea#23330)
  add user visibility in dashboard navbar (go-gitea#22747)
  Fix panic when getting notes by ref (go-gitea#23372)
  Use CleanPath instead of path.Clean (go-gitea#23371)
  Reduce duplicate and useless code in options (go-gitea#23369)
  Clean Path in Options (go-gitea#23006)
  Do not recognize text files as audio (go-gitea#23355)
  Fix incorrect display for comment context menu  (go-gitea#23343)

# Conflicts:
#	templates/repo/issue/view_content/context_menu.tmpl
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants