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

Unified Diff: filter/dscache/context.go

Issue 1269113005: A transparent cache for datastore, backed by memcache. (Closed) Base URL: https://github.com/luci/gae.git@add_meta
Patch Set: Created 5 years, 4 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
« no previous file with comments | « doc.go ('k') | filter/dscache/doc.go » ('j') | filter/dscache/dscache_test.go » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filter/dscache/context.go
diff --git a/filter/dscache/context.go b/filter/dscache/context.go
new file mode 100644
index 0000000000000000000000000000000000000000..1f7df9d93b99c8e10e5c6a3a83f415b5a366eac0
--- /dev/null
+++ b/filter/dscache/context.go
@@ -0,0 +1,32 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package dscache
+
+import (
+ ds "github.com/luci/gae/service/datastore"
+ "github.com/luci/gae/service/info"
+ mc "github.com/luci/gae/service/memcache"
+ "github.com/luci/luci-go/common/logging"
+ "github.com/luci/luci-go/common/mathrand"
+ "golang.org/x/net/context"
+)
+
+type key int
+
+var dsTxnCacheKey key
+
+// FilterRDS installs a counter RawDatastore filter in the context.
+func FilterRDS(c context.Context) context.Context {
+ return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface) ds.RawInterface {
+ i := info.Get(ic)
+ aid, ns := i.AppID(), i.GetNamespace()
+
+ v := ic.Value(dsTxnCacheKey)
+ if v == nil {
+ return &dsCache{ds, aid, ns, mc.Get(ic), logging.Get(ic), mathrand.Get(ic)}
+ }
+ return &dsTxnCache{ds, v.(*dsTxnState), mc.Get(ic)}
+ })
+}
« no previous file with comments | « doc.go ('k') | filter/dscache/doc.go » ('j') | filter/dscache/dscache_test.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698