added filesystem cache and updated logslice to use it.

This commit is contained in:
pnispel 2014-05-22 13:47:22 -07:00
Родитель ace3d2bd4c
Коммит dbd00f1455
2 изменённых файлов: 21 добавлений и 3 удалений

Просмотреть файл

@ -257,6 +257,12 @@ CACHES = {
"TIMEOUT": 0,
# bumping this is effectively equivalent to restarting memcached
"VERSION": 1,
},
"filesystem": {
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
"LOCATION": "/var/tmp/django_cache",
"VERSION": 1
}
}

Просмотреть файл

@ -1,6 +1,6 @@
from rest_framework import viewsets
from rest_framework.response import Response
from django.core.cache import cache
from django.core import cache
from treeherder.webapp.api.utils import (UrlQueryFilter, with_jobs)
@ -11,6 +11,8 @@ import gzip
import io
import logging
filesystem = cache.get_cache('filesystem')
class LogSliceView(viewsets.ViewSet):
"""
This view serves slices of the log
@ -43,8 +45,18 @@ class LogSliceView(viewsets.ViewSet):
job = objs[0]
try:
handle = self.get_log_handle( job.get("blob").get("logurl") )
url = job.get("blob").get("logurl")
gz_file = filesystem.get(url)
if not gz_file:
print('miss')
handle = self.get_log_handle(url)
gz_file = gzip.GzipFile(fileobj=io.BytesIO(handle.read()))
filesystem.set(url, gz_file.fileobj)
else:
print('hit')
gz_file = gzip.GzipFile(fileobj=gz_file)
lines = []