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

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

Issue 15087006: Docserver: there is only one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better redirects Created 7 years, 7 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
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 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 from datetime import datetime, timedelta 5 from datetime import datetime, timedelta
6 from file_system import FileNotFoundError, ToUnicode 6 from file_system import FileNotFoundError, ToUnicode
7 from future import Future 7 from future import Future
8 from patcher import Patcher 8 from patcher import Patcher
9 9
10 _VERSION_CACHE_MAXAGE = timedelta(seconds=5) 10 _VERSION_CACHE_MAXAGE = timedelta(seconds=5)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 ''' CachingRietveldPatcher implements a caching layer on top of |patcher|. 59 ''' CachingRietveldPatcher implements a caching layer on top of |patcher|.
60 In theory, it can be used with any class that implements Patcher. But this 60 In theory, it can be used with any class that implements Patcher. But this
61 class assumes that applying to all patched files at once is more efficient 61 class assumes that applying to all patched files at once is more efficient
62 than applying to individual files. 62 than applying to individual files.
63 ''' 63 '''
64 def __init__(self, 64 def __init__(self,
65 rietveld_patcher, 65 rietveld_patcher,
66 object_store_creator, 66 object_store_creator,
67 test_datetime=datetime): 67 test_datetime=datetime):
68 self._patcher = rietveld_patcher 68 self._patcher = rietveld_patcher
69 self._version_object_store = object_store_creator.Create( 69 def create_object_store(category):
70 CachingRietveldPatcher, category='version') 70 return object_store_creator.Create(
71 self._list_object_store = object_store_creator.Create( 71 CachingRietveldPatcher,
72 CachingRietveldPatcher, category='list') 72 category='%s/%s' % (rietveld_patcher.GetIdentity(), category))
73 self._file_object_store = object_store_creator.Create( 73 self._version_object_store = create_object_store('version')
74 CachingRietveldPatcher, category='file') 74 self._list_object_store = create_object_store('list')
75 self._file_object_store = create_object_store('file')
75 self._datetime = test_datetime 76 self._datetime = test_datetime
76 77
77 def GetVersion(self): 78 def GetVersion(self):
78 key = 'version' 79 key = 'version'
79 value = self._version_object_store.Get(key).Get() 80 value = self._version_object_store.Get(key).Get()
80 if value is not None: 81 if value is not None:
81 version, time = value 82 version, time = value
82 if self._datetime.now() - time < _VERSION_CACHE_MAXAGE: 83 if self._datetime.now() - time < _VERSION_CACHE_MAXAGE:
83 return version 84 return version
84 85
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return _AsyncUncachedFuture(version, 117 return _AsyncUncachedFuture(version,
117 paths, 118 paths,
118 binary, 119 binary,
119 cached_value, 120 cached_value,
120 missing_paths, 121 missing_paths,
121 self._patcher.Apply(set(added) | set(modified), 122 self._patcher.Apply(set(added) | set(modified),
122 None, 123 None,
123 True, 124 True,
124 version), 125 version),
125 self._file_object_store) 126 self._file_object_store)
127
128 def GetIdentity(self):
129 return self._patcher.GetIdentity()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698