You can download this code by clicking the button below.
This code is now available for download.
This function calls a cached random number generator and returns the sum of two arguments.
Technology Stack : flask-caching, Flask, random
Code Type : Function
Code Difficulty : Intermediate
from flask_caching import Cache
from flask import Flask
import random
app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
@cache.cached(timeout=50, key_prefix='my_cache')
def get_random_number():
return random.randint(1, 100)
def xxx(arg1, arg2):
return get_random_number(), arg1 + arg2