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

Side by Side 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: add test for per-model expiration 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 unified diff | Download patch
« no previous file with comments | « no previous file | filter/dscache/doc.go » ('j') | filter/dscache/doc.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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.
Vadim Sh. 2015/08/06 01:23:33 not a counter
iannucci 2015/08/06 02:37:33 erp
21 //
22 // shardsForKey is a user-controllable function which calculates the number of
23 // shards to use for a certain datastore key. The provided key will always be
24 // valid and complete.
25 //
26 // The # of shards returned may be between 1 and 256. Values above this range
27 // will be clamped into that range. A return value of 0 means that NO cache
28 // operations should be done for this key, regardless of the dscache.enable
29 // setting.
30 //
31 // If shardsForKey is nil, the value of DefaultShards is used for all keys.
32 func FilterRDS(c context.Context, shardsForKey func(ds.Key) int) context.Context {
33 return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface) ds.RawInterface {
34 i := info.Get(ic)
35
36 sc := &supportContext{
37 i.AppID(),
38 i.GetNamespace(),
39 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
40 mc.Get(ic),
41 mathrand.Get(ic),
42 shardsForKey,
43 }
44
45 v := ic.Value(dsTxnCacheKey)
46 if v == nil {
47 return &dsCache{ds, sc}
48 }
49 return &dsTxnCache{ds, v.(*dsTxnState), sc}
50 })
51 }
OLDNEW
« no previous file with comments | « no previous file | filter/dscache/doc.go » ('j') | filter/dscache/doc.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698