"""Implements various decorators"""
import logging
from functools import wraps
LOGGER = logging.getLogger('robottelo')
OBJECT_CACHE = {}
[docs]def cacheable(func):
"""Decorator that makes an optional object cache available"""
@wraps(func)
def cacheable_function(options=None, cached=False):
"""
This is the function being returned.
Requires input function's name start with 'make_'
"""
object_key = func.__name__.replace('make_', '')
if cached is True and object_key in OBJECT_CACHE:
return OBJECT_CACHE[object_key]
new_object = func(options)
if cached is True:
OBJECT_CACHE[object_key] = new_object
return new_object
return cacheable_function