Struct zookeeper_async::recipes::cache::PathChildrenCache
source · pub struct PathChildrenCache { /* private fields */ }
Expand description
A Path Cache is used to watch a znode.
A utility that attempts to keep all data from all children of a ZK path locally cached. This will watch the ZK path; whenever a child is added, updated or removed, the Path Cache will change its state to contain the current set of children, the children’s data and the children’s state. You can register a listener that will get notified when changes occur.
§Note
It is not possible to stay transactionally in sync. Users of this class must be prepared for false-positives and false-negatives. Additionally, always use the version number when updating data to avoid overwriting another process’s change.
Implementations§
source§impl PathChildrenCache
impl PathChildrenCache
sourcepub async fn new(zk: Arc<ZooKeeper>, path: &str) -> ZkResult<PathChildrenCache>
pub async fn new(zk: Arc<ZooKeeper>, path: &str) -> ZkResult<PathChildrenCache>
Create a new cache instance watching path
. If path
does not exist, it will be created
(see ZooKeeperExt::ensure_path
).
§Note
After creating the instance, you must call start
.
sourcepub async fn get_current_data(&self) -> Data
pub async fn get_current_data(&self) -> Data
Return the current data. There are no guarantees of accuracy. This is merely the most recent view of the data.
pub async fn clear(&self)
sourcepub fn start(&mut self) -> ZkResult<()>
pub fn start(&mut self) -> ZkResult<()>
Start the cache. The cache is not started automatically. You must call this method.