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

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: epic rebase Created 7 years, 5 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 ''' CachingRietveldPatcher implements a caching layer on top of |patcher|. 60 ''' CachingRietveldPatcher implements a caching layer on top of |patcher|.
61 In theory, it can be used with any class that implements Patcher. But this 61 In theory, it can be used with any class that implements Patcher. But this
62 class assumes that applying to all patched files at once is more efficient 62 class assumes that applying to all patched files at once is more efficient
63 than applying to individual files. 63 than applying to individual files.
64 ''' 64 '''
65 def __init__(self, 65 def __init__(self,
66 rietveld_patcher, 66 rietveld_patcher,
67 object_store_creator, 67 object_store_creator,
68 test_datetime=datetime): 68 test_datetime=datetime):
69 self._patcher = rietveld_patcher 69 self._patcher = rietveld_patcher
70 self._version_object_store = object_store_creator.Create( 70 def create_object_store(category):
71 CachingRietveldPatcher, category='version') 71 return object_store_creator.Create(
72 self._list_object_store = object_store_creator.Create( 72 CachingRietveldPatcher,
73 CachingRietveldPatcher, category='list') 73 category='%s/%s' % (rietveld_patcher.GetIdentity(), category))
74 self._file_object_store = object_store_creator.Create( 74 self._version_object_store = create_object_store('version')
75 CachingRietveldPatcher, category='file') 75 self._list_object_store = create_object_store('list')
76 self._file_object_store = create_object_store('file')
76 self._datetime = test_datetime 77 self._datetime = test_datetime
77 78
78 def GetVersion(self): 79 def GetVersion(self):
79 key = 'version' 80 key = 'version'
80 value = self._version_object_store.Get(key).Get() 81 value = self._version_object_store.Get(key).Get()
81 if value is not None: 82 if value is not None:
82 version, time = value 83 version, time = value
83 if self._datetime.now() - time < _VERSION_CACHE_MAXAGE: 84 if self._datetime.now() - time < _VERSION_CACHE_MAXAGE:
84 return version 85 return version
85 86
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 return _AsyncUncachedFuture(version, 118 return _AsyncUncachedFuture(version,
118 paths, 119 paths,
119 binary, 120 binary,
120 cached_value, 121 cached_value,
121 missing_paths, 122 missing_paths,
122 self._patcher.Apply(set(added) | set(modified), 123 self._patcher.Apply(set(added) | set(modified),
123 None, 124 None,
124 True, 125 True,
125 version), 126 version),
126 self._file_object_store) 127 self._file_object_store)
128
129 def GetIdentity(self):
130 return self._patcher.GetIdentity()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698