Dogpile lock class.
Provides an interface around an arbitrary mutex that allows one thread/process to be elected as the creator of a new value, while other threads/processes continue to return the previous version of that value.
New in version 0.4.0: The Lock class was added as a single-use object representing the dogpile API without dependence on any shared state between multiple instances.
Parameters: |
|
---|
An exception that when raised in the ‘with’ block, forces the ‘has_value’ flag to False and incurs a regeneration of the value.
A mutex which allows multiple readers, single writer.
ReadWriteMutex uses a Python threading.Condition to provide this functionality across threads within a process.
The Beaker package also contained a file-lock based version of this concept, so that readers/writers could be synchronized across processes with a common filesystem. A future Dogpile release may include this additional class at some point.
Acquire the ‘read’ lock.
Acquire the ‘write’ lock.
Release the ‘read’ lock.
Release the ‘write’ lock.
Generates and return an object, keeping it as a singleton for a certain identifier for as long as its strongly referenced.
e.g.:
class MyFoo(object):
"some important object."
def __init__(self, identifier):
self.identifier = identifier
registry = NameRegistry(MyFoo)
# thread 1:
my_foo = registry.get("foo1")
# thread 2
my_foo = registry.get("foo1")
Above, my_foo in both thread #1 and #2 will be the same object. The constructor for MyFoo will be called once, passing the identifier foo1 as the argument.
When thread 1 and thread 2 both complete or otherwise delete references to my_foo, the object is removed from the NameRegistry as a result of Python garbage collection.
Parameters: | creator – A function that will create a new value, given the identifier passed to the NameRegistry.get() method. |
---|
Get and possibly create the value.
Parameters: |
|
---|
Dogpile lock class.
Deprecated since version 0.4.0: The Lock object specifies the full API of the Dogpile object in a single way, rather than providing multiple modes of usage which don’t necessarily work in the majority of cases. Dogpile is now a wrapper around the Lock object which provides dogpile.core’s original usage pattern. This usage pattern began as something simple, but was not of general use in real-world caching environments without several extra complicating factors; the Lock object presents the “real-world” API more succinctly, and also fixes a cross-process concurrency issue.
Parameters: |
|
---|
Acquire the lock, returning a context manager.
Parameters: |
|
---|
The last known ‘creation time’ of the value, stored as an epoch (i.e. from time.time()).
If the value here is -1, it is assumed the value should recreate immediately.
Return true if the creation function has proceeded at least once.
Return true if the expiration time is reached, or no value is available.
Provide a read-write lock function on top of the Dogpile class.
Deprecated since version 0.4.0: The ReadWriteMutex object can be used directly.
Return the “write” lock context manager.
This will provide a section that is mutexed against all readers/writers for the dogpile-maintained value.