add download_url cache

super_signature
nineven 5 years ago
parent 986e179bba
commit d8e4702632
  1. 13
      fir_ser/api/utils/storage/storage.py
  2. 4
      fir_ser/api/views/login.py

@ -8,8 +8,9 @@ from api.models import AppStorage, UserInfo
from .aliyunApi import AliYunOss
from .qiniuApi import QiNiuOss
from .localApi import LocalStorage
import json
import json,time
from fir_ser import settings
from django.core.cache import cache
class Storage(object):
@ -22,7 +23,15 @@ class Storage(object):
def get_download_url(self, filename, expires=900,ftype=None):
if self.storage:
return self.storage.get_download_url(filename, expires,ftype)
now = time.time()
download_val = cache.get("%s_%s"%('download_url',filename))
if download_val:
if download_val.get("time") > now - 60:
return download_val.get("download_url")
download_url=self.storage.get_download_url(filename, expires,ftype)
cache.set("%s_%s"%('download_url',filename),{"download_url":download_url,"time":now+expires},expires)
return download_url
def delete_file(self, filename, apptype=None):
if self.storage:

@ -23,10 +23,10 @@ class LoginView(APIView):
receive = request.data
if request.method == 'POST':
print(receive)
# print(receive)
# is_valid = verify(receive)
is_valid = True
print("is_valid", is_valid)
# print("is_valid", is_valid)
if is_valid:
username = receive.get("username")
password = receive.get("password")

Loading…
Cancel
Save