def _GetSamplesJSON(self, request, key, update=False): templates = self.template_data_source_factory.Create( request, key + '/samples.html') if key == 'apps' or key == 'extensions': cache_url = None if key == 'apps': cache_url = '/trunk/' + key else: cache_url = '/' + templates._branch_info['current'] + '/' + key logging.info('Serving API request %s' % cache_url) data = ResponseCache.Get(cache_url) age = ResponseCache.GetAge(cache_url) need_update = (age > datetime.timedelta(1)) logging.info('Cache age: %s' % str(age)) if data is not None and not (update == True and need_update == True): return data else: content = [] try: logging.info('Trying to generate samples.json for %s' % cache_url) content = templates._samples_data_source.GetAsJSON(key) except: logging.getLogger('slave-samples-api').exception( 'Error generating samples!') pass if len(content) > 0: logging.info('samples.json saved for %s' % cache_url) ResponseCache.Set(cache_url, content) return content
def _GetDocsHTML(self, request, path, update=False): templates = self.template_data_source_factory.Create(request, path) cache_url = '/' + templates._branch_info['current'] + '/' + path logging.info('Serving API request %s' % cache_url) data = ResponseCache.Get(cache_url) age = ResponseCache.GetAge(cache_url) need_update = (age > datetime.timedelta(1)) logging.info('Cache age: %s' % str(age)) if data is not None and not (update == True and need_update == True): return data else: content = '' try: logging.info('Trying to render %s' % cache_url) content = templates.Render(path) except: logging.getLogger('slave-docs-api').exception( 'Error rendering HTML!') pass if len(content) > 0: logging.info('HTML saved for %s' % cache_url) ResponseCache.Set(cache_url, content.encode('utf-8')) return content