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)} |
+ }) |
+} |