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

Side by Side Diff: chrome/common/extensions/docs/server2/object_store_creator.py

Issue 13470005: Refactor the devserver to make it easier to control caching (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cduvall, rebase Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2013 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 from in_memory_object_store import InMemoryObjectStore
6 from memcache_object_store import MemcacheObjectStore
7
8 class ObjectStoreCreator(object):
9 def __init__(self, cls, store_type=None):
10 '''Creates stores with a top-level namespace given by the name of |cls|.
11 Set an explicit |store_type| if necessary for tests.
12
13 By convention this should be the name of the class which owns the object
14 store. If a class needs multiple object store it should use Create with the
15 |category| argument.
16 '''
17 assert isinstance(cls, type)
18 assert not cls.__name__[0].islower() # guard against non-class types
19 self._name = cls.__name__
20 self._store_type = store_type
21
22 def Create(self, version=None, category=None):
23 '''Creates a new object store with the top namespace given in the
24 constructor, at version |version|, with an optional |category| for classes
25 that need multiple object stores (e.g. one for stat and one for read).
26 '''
27 namespace = self._name
28 if category is not None:
29 assert not any(c.isdigit() for c in category)
30 namespace = '%s/%s' % (namespace, category)
31 if version is not None:
32 assert isinstance(version, int)
33 namespace = '%s/%s' % (namespace, version)
34 if self._store_type is not None:
35 return self._store_type(namespace)
36 return InMemoryObjectStore(MemcacheObjectStore(namespace))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698