OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package dscache |
| 6 |
| 7 import ( |
| 8 ds "github.com/luci/gae/service/datastore" |
| 9 "github.com/luci/gae/service/info" |
| 10 mc "github.com/luci/gae/service/memcache" |
| 11 "github.com/luci/luci-go/common/logging" |
| 12 "github.com/luci/luci-go/common/mathrand" |
| 13 "golang.org/x/net/context" |
| 14 ) |
| 15 |
| 16 type key int |
| 17 |
| 18 var dsTxnCacheKey key |
| 19 |
| 20 // FilterRDS installs a counter RawDatastore filter in the context. |
| 21 func FilterRDS(c context.Context) context.Context { |
| 22 return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface)
ds.RawInterface { |
| 23 i := info.Get(ic) |
| 24 aid, ns := i.AppID(), i.GetNamespace() |
| 25 |
| 26 v := ic.Value(dsTxnCacheKey) |
| 27 if v == nil { |
| 28 return &dsCache{ds, aid, ns, mc.Get(ic), logging.Get(ic)
, mathrand.Get(ic)} |
| 29 } |
| 30 return &dsTxnCache{ds, v.(*dsTxnState), mc.Get(ic)} |
| 31 }) |
| 32 } |
OLD | NEW |