Repository navigation
feat(cache): implement per-table tagging and raw SQL bypass #119
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
Changes from all commits
5d0ec08
0e95298
87d578e
d0c2880
a38fa69
41efec7
8960bb2
1347c02
8fc97a6
79f4258
9afeefa
f73c424
1148a02
a208da9
4e50cab
86e85eb
976f793
2898cb2
f5269d8
e0c9bbb
0f606a3
63e3b70
47aff71
3604b56
735d060
fe97e13
d8f7b5c
755985a
9b522c8
348b5ea
593304a
2652fd3
d1d18a0
eff476d
28622d4
9c1bb4f
57d4e19
24bcf54
246a1fa
9052b8b
381d3d3
c577ab8
ac2ed2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package api | |
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "log/slog" | ||
| "net/http" | ||
| "time" | ||
|
|
||
|
|
@@ -17,12 +18,12 @@ import ( | |
| type PipesHandler struct { | ||
| Store *pipes.Store | ||
| CHConn driver.Conn | ||
| Cache *cache.TieredCache | ||
| Cache cache.Cache | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? Why not leave as |
||
| DefaultTTL time.Duration | ||
| sf singleflight.Group | ||
| } | ||
|
|
||
| func NewPipesHandler(store *pipes.Store, conn driver.Conn, c *cache.TieredCache, defaultTTL time.Duration) *PipesHandler { | ||
| func NewPipesHandler(store *pipes.Store, conn driver.Conn, c cache.Cache, defaultTTL time.Duration) *PipesHandler { | ||
| return &PipesHandler{Store: store, CHConn: conn, Cache: c, DefaultTTL: defaultTTL} | ||
| } | ||
|
|
||
|
|
@@ -134,7 +135,6 @@ func (h *PipesHandler) Execute(w http.ResponseWriter, r *http.Request) { | |
| } | ||
| } | ||
|
|
||
| // Execute with singleflight. | ||
| v, err, _ := h.sf.Do(cacheKey, func() (interface{}, error) { | ||
| queryCtx, cancel := context.WithTimeout(r.Context(), 30*time.Second) | ||
| defer cancel() | ||
|
|
@@ -151,7 +151,20 @@ func (h *PipesHandler) Execute(w http.ResponseWriter, r *http.Request) { | |
| } | ||
|
|
||
| if h.Cache != nil { | ||
| _ = h.Cache.Set(r.Context(), cacheKey, data, h.DefaultTTL) | ||
| cleanedSQL := cleanSQLForTags(sql) | ||
| tags := extractCacheTagsFromCleaned(cleanedSQL) | ||
|
|
||
| // Detach from r.Context() so a cancelled originating request doesn't | ||
| // abort the cache populate — singleflight followers may already have | ||
| // received the result, and the next request should be served warm. | ||
| setCtx, setCancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer setCancel() | ||
| if err := h.Cache.Set(setCtx, cacheKey, data, h.DefaultTTL, tags); err != nil { | ||
| slog.WarnContext(r.Context(), "cache set failed for pipe execution", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this not be the same context as the |
||
| "key", cacheKey, | ||
| "error", err, | ||
| ) | ||
| } | ||
| } | ||
| return data, nil | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.