def __init__(self, session, cache, heuristic, transform=None, limiter=None, max_inflight=0):
"""
:param session: requests session to use
:param cache: cache to use
:param heuristic: function that accepts a partially constructed Response object (with only
`expiry` set to `None`) and returns the number of seconds this data will be fresh for.
:param transform: function that accepts a partially constructed Response object (with `expiry` and
`transformed` still set to `None`) and returns any object to represent this data, which may be used
to determine the result's lifetime
:param limiter: This object is called once every time the network is accessed. Any returned data is discarded.
"""
self.session = session
self.cache = cache
self.heuristic = heuristic
self.transform = transform or (lambda x: None)
self.limiter = limiter or (lambda: None)
if max_inflight > 0:
self.inflight = Semaphore(max_inflight)
else:
self.inflight = None
评论列表
文章目录