Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: logdog/appengine/coordinator/coordinatorTest/storage_cache.go

Issue 2435113002: LogDog: Add Storage-layer data caching. (Closed)
Patch Set: Fix byteLimit bug. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: logdog/appengine/coordinator/coordinatorTest/storage_cache.go
diff --git a/logdog/appengine/coordinator/coordinatorTest/storage_cache.go b/logdog/appengine/coordinator/coordinatorTest/storage_cache.go
new file mode 100644
index 0000000000000000000000000000000000000000..594cbef4c0df5a92820d5c035bf826034b050b21
--- /dev/null
+++ b/logdog/appengine/coordinator/coordinatorTest/storage_cache.go
@@ -0,0 +1,70 @@
+// Copyright 2016 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package coordinatorTest
+
+import (
+ "sync"
+ "time"
+
+ "github.com/luci/luci-go/logdog/common/storage/caching"
+
+ "golang.org/x/net/context"
+)
+
+// StorageCache wraps the default storage cache instance, adding tracking
+// information that is useful for testing.
+type StorageCache struct {
+ Base caching.Cache
+
+ statsMu sync.Mutex
+ stats StorageCacheStats
+}
+
+// StorageCacheStats expose stats for a StorageCache instance.
+type StorageCacheStats struct {
+ Puts int
+ Hits int
+ Misses int
+}
+
+// Clear clears the stats for this cache instance.
+func (sc *StorageCache) Clear() {
+ sc.statsMu.Lock()
+ defer sc.statsMu.Unlock()
+ sc.stats = StorageCacheStats{}
+}
+
+// Stats returns the stats for this cache instance.
+func (sc *StorageCache) Stats() StorageCacheStats {
+ sc.statsMu.Lock()
+ defer sc.statsMu.Unlock()
+ return sc.stats
+}
+
+// Get implements caching.Cache.
+func (sc *StorageCache) Get(c context.Context, items ...*caching.Item) {
+ sc.Base.Get(c, items...)
+
+ // Calculate our hit/misses from the result.
+ sc.statsMu.Lock()
+ defer sc.statsMu.Unlock()
+ for _, it := range items {
+ if it.Data != nil {
+ sc.stats.Hits++
+ } else {
+ sc.stats.Misses++
+ }
+ }
+
+}
+
+// Put implements caching.Cache.
+func (sc *StorageCache) Put(c context.Context, exp time.Duration, items ...*caching.Item) {
+ sc.Base.Put(c, exp, items...)
+
+ sc.statsMu.Lock()
+ defer sc.statsMu.Unlock()
+ sc.stats.Puts += len(items)
+}
« no previous file with comments | « logdog/appengine/coordinator/coordinatorTest/service.go ('k') | logdog/appengine/coordinator/endpoints/logs/get.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698