Change the cache key abit and extended cache time

This commit is contained in:
Jeremy Zhang 2017-05-08 21:44:05 -07:00
parent ed0131fb10
commit d29d70565d
2 changed files with 7 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import json
from requests_oauthlib import OAuth2Session from requests_oauthlib import OAuth2Session
from flask import session, abort, url_for from flask import session, abort, url_for
from titanembeds.database import get_keyvalproperty, set_keyvalproperty from titanembeds.database import get_keyvalproperty, set_keyvalproperty
from titanembeds.utils import make_cache_key from titanembeds.utils import make_user_cache_key
authorize_url = "https://discordapp.com/api/oauth2/authorize" authorize_url = "https://discordapp.com/api/oauth2/authorize"
token_url = "https://discordapp.com/api/oauth2/token" token_url = "https://discordapp.com/api/oauth2/token"
@ -52,7 +52,7 @@ def get_user_guilds():
if req.status_code != 200: if req.status_code != 200:
abort(req.status_code) abort(req.status_code)
req = json.dumps(req.json()) req = json.dumps(req.json())
set_keyvalproperty("OAUTH/USERGUILDS/"+make_cache_key(), req, 100) set_keyvalproperty("OAUTH/USERGUILDS/"+make_user_cache_key(), req, 250)
return req return req
def get_user_managed_servers(): def get_user_managed_servers():

View File

@ -32,6 +32,11 @@ def make_cache_key(*args, **kwargs):
sess = generate_session_key() sess = generate_session_key()
return (path + args + sess + ip).encode('utf-8') return (path + args + sess + ip).encode('utf-8')
def make_user_cache_key(*args, **kwargs)
ip = get_client_ipaddr()
sess = generate_session_key()
return (sess + ip).encode('utf-8')
def make_guilds_cache_key(): def make_guilds_cache_key():
sess = generate_session_key() sess = generate_session_key()
ip = get_client_ipaddr() ip = get_client_ipaddr()