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

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

Issue 10500004: Die build.py, Die: Part 2 (LocalFetcher, Handlebar support, build script) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: TemplateFetcher now has dictionary interface Created 8 years, 6 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
OLDNEW
(Empty)
1 # Copyright (c) 2012 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 import logging
6 import os
7 import time
8
9 from third_party.handlebar import Handlebar
10
11 # Cache templates for 5 minutes.
12 CACHE_TIMEOUT = 300
13
14 # Cached templates stored as (branch, path) -> (template, cache time)
15 # The template cache is global so it will not be erased each time a new
16 # TemplateFetcher is created.
17 TEMPLATE_CACHE = {}
18
19 class TemplateFetcher(object):
20 def __init__(self, branch, fetcher):
21 self._fetcher = fetcher
22 self._branch = branch
23
24 def __getitem__(self, key):
25 if (self._branch, key) not in TEMPLATE_CACHE:
Aaron Boodman 2012/06/05 00:50:04 Nit: Is there a reason for FetchTemplate() now? It
not at google - send to devlin 2012/06/05 00:56:10 Python style guide reasons?
cduvall 2012/06/05 01:07:37 I moved it for now we can move it back out to Fetc
26 self.FetchTemplate(key)
27 return TEMPLATE_CACHE[(self._branch, key)][0]
28
29 def FetchTemplate(self, path):
30 key = (self._branch, path)
31 # Check the template cache and whether the cache has expired.
32 if key in TEMPLATE_CACHE:
33 if TEMPLATE_CACHE[key][1] < CACHE_TIMEOUT:
Aaron Boodman 2012/06/05 00:50:04 Indexing tuples by number like this always looks u
Aaron Boodman 2012/06/05 00:50:04 Does this work? Seems like you need to subtract fr
Aaron Boodman 2012/06/05 00:50:04 kalman is right that this is going to be a pain es
cduvall 2012/06/05 01:07:37 Done.
cduvall 2012/06/05 01:07:37 Done.
cduvall 2012/06/05 01:07:37 Agreed, I'll do that in the next CL.
34 return TEMPLATE_CACHE[key][0]
35 logging.info('Template cache miss for: ' + path)
36 template = self._fetcher.FetchResource(self._branch, path).content
37 compiled_template = Handlebar(template)
38 TEMPLATE_CACHE[key] = (compiled_template, time.clock())
39 return compiled_template
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698