MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / OpenReader

Method OpenReader

internal/caches/storage_memory.go:129–167  ·  view source on GitHub ↗

OpenReader 读取缓存

(key string, useStale bool, isPartial bool)

Source from the content-addressed store, hash-verified

127
128// OpenReader 读取缓存
129func (this *MemoryStorage) OpenReader(key string, useStale bool, isPartial bool) (Reader, error) {
130 var hash = this.hash(key)
131
132 // check if exists in list
133 exists, _, _ := this.list.Exist(types.String(hash))
134 if !exists {
135 return nil, ErrNotFound
136 }
137
138 // read from valuesMap
139 this.locker.RLock()
140 var item = this.valuesMap[hash]
141
142 if item != nil {
143 item.isReferring = true
144 }
145
146 if item == nil || !item.IsDone {
147 this.locker.RUnlock()
148 return nil, ErrNotFound
149 }
150
151 if useStale || (item.ExpiresAt > fasttime.Now().Unix()) {
152 var reader = NewMemoryReader(item)
153 err := reader.Init()
154 if err != nil {
155 this.locker.RUnlock()
156 return nil, err
157 }
158 this.locker.RUnlock()
159
160 return reader, nil
161 }
162 this.locker.RUnlock()
163
164 _ = this.Delete(key)
165
166 return nil, ErrNotFound
167}
168
169// OpenWriter 打开缓存写入器等待写入
170func (this *MemoryStorage) OpenWriter(key string, expiredAt int64, status int, headerSize int, bodySize int64, maxSize int64, isPartial bool) (Writer, error) {

Callers 1

Calls 10

hashMethod · 0.95
DeleteMethod · 0.95
NowFunction · 0.92
NewMemoryReaderFunction · 0.85
RLockMethod · 0.80
RUnlockMethod · 0.80
UnixMethod · 0.80
ExistMethod · 0.65
InitMethod · 0.65
StringMethod · 0.45

Tested by 1