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

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

Issue 10545043: Extensions docs server: Design changes, partial template support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made suggested changes 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 | Annotate | Revision Log
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, path):
25 key = (self._branch, path)
26 if key in TEMPLATE_CACHE:
27 compiled_template, compile_time = TEMPLATE_CACHE[key]
28 if (time.clock() - compile_time) > CACHE_TIMEOUT:
29 TEMPLATE_CACHE.pop(key)
30 if key not in TEMPLATE_CACHE:
31 logging.info('Template cache miss for: ' + path)
32 try:
33 template = self._fetcher.FetchResource(self._branch, path).content
34 compiled_template = Handlebar(template)
35 TEMPLATE_CACHE[key] = (compiled_template, time.clock())
36 except:
37 return ''
38
39 return compiled_template
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698