MCPcopy
hub / github.com/writefreely/writefreely / updateTimelineCache

Function updateTimelineCache

read.go:163–182  ·  view source on GitHub ↗

updateTimelineCache will reset and update the cache if it is stale or the boolean passed in is true.

(tl *localTimeline, reset bool)

Source from the content-addressed store, hash-verified

161// updateTimelineCache will reset and update the cache if it is stale or
162// the boolean passed in is true.
163func updateTimelineCache(tl *localTimeline, reset bool) {
164 if reset {
165 tl.m.Reset()
166 }
167
168 // Fetch posts if the cache is empty, has been reset or enough time has
169 // passed since last cache.
170 if tl.posts == nil || reset || tl.m.Invalidate() {
171 log.Info("[READ] Updating post cache")
172
173 postsInterfaces, err := tl.m.Get()
174 if err != nil {
175 log.Error("[READ] Unable to cache posts: %v", err)
176 } else {
177 castPosts := postsInterfaces.([]PublicPost)
178 tl.posts = &castPosts
179 }
180 }
181
182}
183
184func showLocalTimeline(app *App, w http.ResponseWriter, r *http.Request, page int, author, tag string) error {
185 updateTimelineCache(app.timeline, false)

Callers 4

viewLocalTimelineAPIFunction · 0.85
showLocalTimelineFunction · 0.85
viewLocalTimelineFeedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected