Minor changes to memoize
Modifying memoize to accept user defined ttl from config and changing the way unique id is calculated. Change-Id: Icda4e105bb9ead8edeaef089b677a83d1fa6f9d4
This commit is contained in:
parent
54b76d261f
commit
69c06f1644
|
@ -239,7 +239,9 @@ def list_user_opts():
|
|||
cfg.StrOpt("serialize_format", default="json",
|
||||
help="Type of request body"),
|
||||
cfg.StrOpt("deserialize_format", default="json",
|
||||
help="Type of response body")
|
||||
help="Type of response body"),
|
||||
cfg.IntOpt("token_ttl", default=1800,
|
||||
help="Time to live for token in seconds")
|
||||
|
||||
]
|
||||
|
||||
|
|
|
@ -12,9 +12,12 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from functools import wraps
|
||||
from hashlib import md5
|
||||
from time import time
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
def memoize(func):
|
||||
"""Caches the result of a function call
|
||||
|
@ -25,8 +28,8 @@ def memoize(func):
|
|||
|
||||
@wraps(func)
|
||||
def decorate(*args, **kwargs):
|
||||
ttl = time() + 1800
|
||||
func_id = md5(str(func.__name__) + str(args) + str(kwargs)).digest()
|
||||
ttl = time() + CONF.user.token_ttl
|
||||
func_id = args, frozenset(kwargs.items())
|
||||
if memoized_calls.get(func_id):
|
||||
time_left = memoized_calls[func_id]["ttl"] - time()
|
||||
if time_left > 0:
|
||||
|
|
Loading…
Reference in New Issue