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
70 self.allow_attr_cache = True
71 self.allow_dirent_cache = True
73 # Mark the value as stale
77 # Test if the entries dict is stale.
82 return (self._last_update + self._poll_time) < self._atime
87 self._last_update = time.time()
99 return self.use_count > 0
109 return self.ref_count
111 def dec_ref(self, n):
113 return self.ref_count
115 def has_ref(self, only_children=False):
116 return self.ref_count > 0