Jul-02-2020, 03:34 PM
Hi all, I'm studying Python and I should write a function in Python that check whether a user has fetched some url or not through his web browser. I read about the implementation of a fetch(url) function as follows:
It should be something like:
Thank you very much in advance for any help!
_cache = {} def fetch(url): user = os.environ['USER'] if user not in _cache: _cache[user] = {} if url not in _cache[user]: _cache[user][url] = requests.get(url).content return _cache[user][url]and I'm trying to figure out how to modify this kind of function in order it checks wether a user has fetched some url or not, assuming that fetching a resource from web might take 0.1 seconds, while fetching it on the cache provides an instant result.
It should be something like:
import sys # ignore sys.path.insert(0,'.') # ignore from Root.fetch import fetch def did_fetch(user, url): pass #REQUIRED FUNCTION THAT RETURN IF URL HAS BEEN FECTHED BY USERwith the function to be implemented inside.
Thank you very much in advance for any help!
