| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package dscache | 5 package dscache |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 ds "github.com/luci/gae/service/datastore" | 8 ds "github.com/luci/gae/service/datastore" |
| 9 "github.com/luci/gae/service/info" | 9 "github.com/luci/gae/service/info" |
| 10 mc "github.com/luci/gae/service/memcache" | 10 mc "github.com/luci/gae/service/memcache" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 return AlwaysFilterRDS(c, shardsForKey) | 39 return AlwaysFilterRDS(c, shardsForKey) |
| 40 } | 40 } |
| 41 | 41 |
| 42 // AlwaysFilterRDS installs a caching RawDatastore filter in the context. | 42 // AlwaysFilterRDS installs a caching RawDatastore filter in the context. |
| 43 // | 43 // |
| 44 // Unlike FilterRDS it doesn't check GlobalConfig via IsGloballyEnabled call, | 44 // Unlike FilterRDS it doesn't check GlobalConfig via IsGloballyEnabled call, |
| 45 // assuming caller already knows whether filter should be applied or not. | 45 // assuming caller already knows whether filter should be applied or not. |
| 46 func AlwaysFilterRDS(c context.Context, shardsForKey func(*ds.Key) int) context.
Context { | 46 func AlwaysFilterRDS(c context.Context, shardsForKey func(*ds.Key) int) context.
Context { |
| 47 return ds.AddRawFilters(c, func(c context.Context, ds ds.RawInterface) d
s.RawInterface { | 47 return ds.AddRawFilters(c, func(c context.Context, ds ds.RawInterface) d
s.RawInterface { |
| 48 i := info.Get(c) | 48 i := info.Get(c) |
| 49 ns, _ := i.GetNamespace() |
| 49 | 50 |
| 50 sc := &supportContext{ | 51 sc := &supportContext{ |
| 51 i.AppID(), | 52 i.AppID(), |
| 52 » » » i.GetNamespace(), | 53 » » » ns, |
| 53 c, | 54 c, |
| 54 mc.Get(c), | 55 mc.Get(c), |
| 55 mathrand.Get(c), | 56 mathrand.Get(c), |
| 56 shardsForKey, | 57 shardsForKey, |
| 57 } | 58 } |
| 58 | 59 |
| 59 v := c.Value(dsTxnCacheKey) | 60 v := c.Value(dsTxnCacheKey) |
| 60 if v == nil { | 61 if v == nil { |
| 61 return &dsCache{ds, sc} | 62 return &dsCache{ds, sc} |
| 62 } | 63 } |
| 63 return &dsTxnCache{ds, v.(*dsTxnState), sc} | 64 return &dsTxnCache{ds, v.(*dsTxnState), sc} |
| 64 }) | 65 }) |
| 65 } | 66 } |
| OLD | NEW |