7 """Parse Arvados timestamp to unix time."""
11 return calendar.timegm(ciso8601.parse_datetime_unaware(t).timetuple())
12 except (TypeError, ValueError):
15 def use_counter(orig_func):
16 @functools.wraps(orig_func)
17 def use_counter_wrapper(self, *args, **kwargs):
20 return orig_func(self, *args, **kwargs)
23 return use_counter_wrapper
25 def check_update(orig_func):
26 @functools.wraps(orig_func)
27 def check_update_wrapper(self, *args, **kwargs):
29 return orig_func(self, *args, **kwargs)
30 return check_update_wrapper
32 class FreshBase(object):
33 """Base class for maintaining object lifecycle.
37 * Indicate if an object is up to date (stale() == false) or needs to be
38 updated sets stale() == True). Use invalidate() to mark the object as
39 stale. An object is also automatically stale if it has not been updated
40 in `_poll_time` seconds.
42 * Record access time (atime) timestamp
44 * Manage internal use count used by the inode cache ("inc_use" and
45 "dec_use"). An object which is in use cannot be cleared by the inode
48 * Manage the kernel reference count ("inc_ref" and "dec_ref"). An object
49 which is referenced by the kernel cannot have its inode entry deleted.
51 * Record cache footprint, cache priority
53 * Record Arvados uuid at the time the object is placed in the cache
55 * Clear the object contents (invalidates the object)
61 self._last_update = time.time()
62 self._atime = time.time()
67 self.cache_priority = None
69 self.cache_uuid = None
71 # Mark the value as stale
75 # Test if the entries dict is stale.
80 return (self._last_update + self._poll_time) < self._atime
85 self._last_update = time.time()
93 def clear(self, force=False):
97 return self.use_count > 0
107 return self.ref_count
109 def dec_ref(self, n):
111 return self.ref_count