Upsert a revision in the cache.
(ctx context.Context, docRev DocumentRevision, collectionID uint32)
| 334 | |
| 335 | // Upsert a revision in the cache. |
| 336 | func (rc *LRURevisionCache) Upsert(ctx context.Context, docRev DocumentRevision, collectionID uint32) { |
| 337 | // similar to PUT operation we should have the CV defined by this point (updateHLV is called before calling this) |
| 338 | key := IDandCV{DocID: docRev.DocID, Source: docRev.CV.SourceID, Version: docRev.CV.Value, CollectionID: collectionID} |
| 339 | legacyKey := IDAndRev{DocID: docRev.DocID, RevID: docRev.RevID, CollectionID: collectionID} |
| 340 | |
| 341 | numItemsRemoved, value := rc.upsertDocToCache(ctx, key, legacyKey, docRev, collectionID) |
| 342 | if numItemsRemoved > 0 { |
| 343 | rc.cacheNumItems.Add(-numItemsRemoved) |
| 344 | } |
| 345 | |
| 346 | docRev.CalculateBytes() |
| 347 | // add new item bytes to overall count |
| 348 | rc.incrRevCacheMemoryUsage(ctx, docRev.MemoryBytes) |
| 349 | value.store(docRev) |
| 350 | |
| 351 | // check we aren't over memory capacity, if so perform eviction |
| 352 | rc.revCacheMemoryBasedEviction(ctx) |
| 353 | } |
| 354 | |
| 355 | func (rc *LRURevisionCache) upsertDocToCache(ctx context.Context, cvKey IDandCV, legacyKey IDAndRev, docRev DocumentRevision, collectionID uint32) (int64, *revCacheValue) { |
| 356 | rc.lock.Lock() |