Index: filter/dscache/context.go |
diff --git a/filter/dscache/context.go b/filter/dscache/context.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..56488f2e3c46b810930d5e56c64e318fa05481d8 |
--- /dev/null |
+++ b/filter/dscache/context.go |
@@ -0,0 +1,51 @@ |
+// 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. |
Vadim Sh.
2015/08/06 01:23:33
not a counter
iannucci
2015/08/06 02:37:33
erp
|
+// |
+// shardsForKey is a user-controllable function which calculates the number of |
+// shards to use for a certain datastore key. The provided key will always be |
+// valid and complete. |
+// |
+// The # of shards returned may be between 1 and 256. Values above this range |
+// will be clamped into that range. A return value of 0 means that NO cache |
+// operations should be done for this key, regardless of the dscache.enable |
+// setting. |
+// |
+// If shardsForKey is nil, the value of DefaultShards is used for all keys. |
+func FilterRDS(c context.Context, shardsForKey func(ds.Key) int) context.Context { |
+ return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface) ds.RawInterface { |
+ i := info.Get(ic) |
+ |
+ sc := &supportContext{ |
+ i.AppID(), |
+ i.GetNamespace(), |
+ logging.Get(ic), |
dnj
2015/08/05 18:32:17
Why not retain the context itself, instead of pull
iannucci
2015/08/06 01:54:00
Mer... so... these are all used in inner loops. I
|
+ mc.Get(ic), |
+ mathrand.Get(ic), |
+ shardsForKey, |
+ } |
+ |
+ v := ic.Value(dsTxnCacheKey) |
+ if v == nil { |
+ return &dsCache{ds, sc} |
+ } |
+ return &dsTxnCache{ds, v.(*dsTxnState), sc} |
+ }) |
+} |