MCPcopy
hub / github.com/dosco/graphjin / fragmentCacheGet

Method fragmentCacheGet

core/cache_fragment.go:51–79  ·  view source on GitHub ↗
(
	ctx context.Context,
	key string,
	refresh RefreshFnWithOptions,
)

Source from the content-addressed store, hash-verified

49}
50
51func (s *gstate) fragmentCacheGet(
52 ctx context.Context,
53 key string,
54 refresh RefreshFnWithOptions,
55) ([]byte, bool) {
56 if key == "" || s.gj == nil || s.gj.responseCache == nil {
57 return nil, false
58 }
59 data, isStale, found := s.gj.responseCache.Get(ctx, key)
60 if !found {
61 s.fragmentMisses.Add(1)
62 return nil, false
63 }
64 s.fragmentHits.Add(1)
65 if isStale && refresh != nil {
66 if refresher, ok := s.gj.responseCache.(SWRRefresherWithOptions); ok {
67 refresher.SubmitRefreshWithOptions(key, refresh)
68 } else if refresher, ok := s.gj.responseCache.(SWRRefresher); ok {
69 refresher.SubmitRefresh(key, func() ([]byte, []RowRef, error) {
70 data, refs, opts, err := refresh()
71 if opts.NoStore || opts.HardTTL > 0 || opts.FreshTTL > 0 {
72 return nil, nil, err
73 }
74 return data, refs, err
75 })
76 }
77 }
78 return data, true
79}
80
81func (s *gstate) fragmentCacheSet(
82 ctx context.Context,

Calls 3

GetMethod · 0.65
SubmitRefreshMethod · 0.65