MCPcopy
hub / github.com/gofiber/fiber / get

Method get

middleware/cache/manager.go:110–138  ·  view source on GitHub ↗

get data from storage or memory

(ctx context.Context, key string)

Source from the content-addressed store, hash-verified

108
109// get data from storage or memory
110func (m *manager) get(ctx context.Context, key string) (*item, error) {
111 if m.storage != nil {
112 raw, err := m.storage.GetWithContext(ctx, key)
113 if err != nil {
114 return nil, fmt.Errorf("cache: failed to get key %q from storage: %w", m.logKey(key), err)
115 }
116 if raw == nil {
117 return nil, errCacheMiss
118 }
119
120 it := m.acquire()
121 if _, err := it.UnmarshalMsg(raw); err != nil {
122 m.release(it)
123 return nil, fmt.Errorf("cache: failed to unmarshal key %q: %w", m.logKey(key), err)
124 }
125
126 return it, nil
127 }
128
129 if value := m.memory.Get(key); value != nil {
130 it, ok := value.(*item)
131 if !ok {
132 return nil, fmt.Errorf("cache: unexpected entry type %T for key %q", value, m.logKey(key))
133 }
134 return it, nil
135 }
136
137 return nil, errCacheMiss
138}
139
140// get raw data from storage or memory
141func (m *manager) getRaw(ctx context.Context, key string) ([]byte, error) {

Callers 4

NewFunction · 0.45
Test_manager_getFunction · 0.45

Calls 7

logKeyMethod · 0.95
acquireMethod · 0.95
releaseMethod · 0.95
GetWithContextMethod · 0.65
ErrorfMethod · 0.65
GetMethod · 0.65
UnmarshalMsgMethod · 0.45

Tested by 3

Test_manager_getFunction · 0.36