"""
This module is a wrapper for flask_caching. It configures it and rename
the memoize function. The aim with that cache is to minimize the requests
made on the target database.
"""
import redis

from functools import wraps
from flask_caching import Cache
from zou.app import config


cache = None

try:
    redis_cache = redis.StrictRedis(
        host=config.KEY_VALUE_STORE["host"],
        port=config.KEY_VALUE_STORE["port"],
        db=config.MEMOIZE_DB_INDEX,
        decode_responses=True
    )
    redis_cache.get("test")
    cache = Cache(config={
        "CACHE_TYPE": "redis",
        "CACHE_REDIS_HOST": config.KEY_VALUE_STORE["host"],
        "CACHE_REDIS_PORT": config.KEY_VALUE_STORE["port"],
        "CACHE_REDIS_DB": config.MEMOIZE_DB_INDEX
    })

# This is needed to run tests which. This way they do not require a Redis
# instance to work properly
except redis.ConnectionError:
    cache = Cache(config={
        "CACHE_TYPE": "simple"
    })

memoize_function = cache.memoize


def memoize_function(function, timeout=120):
    function = cache.memoize(function, timeout)

    @wraps(function)
    def wrapper(*args, **kwargs):
        result = function(*args, **kwargs)
        if result is None:
            cache.delete_memoized(function)
            result = function(*args, **kwargs)
        return result

    return wrapper


def clear():
    cache.clear()

@@ -1348,16 +1348,74 @@
 apper%0A%0A%0A
+def invalidate(*args):%0A    cache.delete_memoized(*args)%0A%0A%0A
 def clea

Add a function to unvalidate cache