Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
Every cullFrequency times that an item is retrieved from this cache, the cull method is called.
The cull method then expires an arbitrary fraction of the cached objects. The idea is at no time will the cache be entirely emptied, placing a potentially high load at that moment, but everything object will have its time to go eventually. The fraction is given as an integer, and one in that many objects are expired (i.e., the default is 1/2 of objects are expired).
By setting cache to False, items won't be cached.
However, in all cases a weak reference is kept to created objects, and if the object hasn't been garbage collected it will be returned.
This method can cause deadlocks! tryGet is safer
This returns the object found in cache, or None. If None, then the cache will remain locked! This is so that the calling function can create the object in a threadsafe manner before releasing the lock. You should use this like (note that cache is actually a CacheSet object in this example):
obj = cache.get(some_id, my_class) if obj is None: try: obj = create_object(some_id) cache.put(some_id, my_class, obj) finally: cache.finishPut(cls)
This method checks both the main cache (which retains references) and the 'expired' cache, which retains only weak references.
Puts an object into the cache. Should only be called after .get(), so that duplicate objects don't end up in the cache.
Inserts and object into the cache. Should be used when no one else knows about the object yet, so there cannot be any object already in the cache. After a database INSERT is an example of this situation.
Runs through the cache and expires objects
E.g., if cullFraction is 3, then every third object is moved to the 'expired' (aka weakref) cache.
Removes everything from the cache. Warning! This can cause duplicate objects in memory.
Expires a single object. Typically called after a delete. Doesn't even keep a weakref. (@@: bad name?)
See the source for more information.