Struct concread::arcache::ARCacheWriteTxn
source · pub struct ARCacheWriteTxn<'a, K, V, S>where
K: Hash + Eq + Ord + Clone + Debug + Sync + Send + 'static,
V: Clone + Debug + Sync + Send + 'static,
S: ARCacheWriteStat<K>,{ /* private fields */ }
Expand description
An active write transaction over the cache. The data in this cache is isolated from readers, and may be rolled-back if an error occurs. Changes only become globally visible once you call “commit”. Items may be added to the cache on a miss via “insert”, and you can explicitly remove items by calling “remove”.
Implementations§
source§impl<K: Hash + Eq + Ord + Clone + Debug + Sync + Send + 'static, V: Clone + Debug + Sync + Send + 'static, S: ARCacheWriteStat<K>> ARCacheWriteTxn<'_, K, V, S>
impl<K: Hash + Eq + Ord + Clone + Debug + Sync + Send + 'static, V: Clone + Debug + Sync + Send + 'static, S: ARCacheWriteStat<K>> ARCacheWriteTxn<'_, K, V, S>
sourcepub fn commit(self) -> S
pub fn commit(self) -> S
Commit the changes of this writer, making them globally visible. This causes all items written to this thread’s local store to become visible in the main cache.
To rollback (abort) and operation, just do not call commit (consider std::mem::drop on the write transaction)
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear all items of the cache. This operation does not take effect until you commit. After calling “clear”, you may then include new items which will be stored thread locally until you commit.
sourcepub fn get<Q>(&mut self, k: &Q) -> Option<&V>
pub fn get<Q>(&mut self, k: &Q) -> Option<&V>
Attempt to retieve a k-v pair from the cache. If it is present in the main cache OR
the thread local cache, a Some
is returned, else you will recieve a None
. On a
None
, you must then consult the external data source that this structure is acting
as a cache for.
sourcepub fn get_mut<Q>(&mut self, k: &Q, make_dirty: bool) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, k: &Q, make_dirty: bool) -> Option<&mut V>
If a value is in the thread local cache, retrieve it for mutation. If the value is not in the thread local cache, it is retrieved and cloned from the main cache. If the value had been marked for removal, it must first be re-inserted.
§Safety
Since you are mutating the state of the value, if you have sized insertions you MAY break this since you can change the weight of the value to be inconsistent
sourcepub fn contains_key<Q>(&mut self, k: &Q) -> bool
pub fn contains_key<Q>(&mut self, k: &Q) -> bool
Determine if this cache contains the following key.
sourcepub fn insert(&mut self, k: K, v: V)
pub fn insert(&mut self, k: K, v: V)
Add a value to the cache. This may be because you have had a cache miss and now wish to include in the thread local storage, or because you have written a new value and want it to be submitted for caching. This item is marked as clean, IE you have synced it to whatever associated store exists.
sourcepub fn insert_sized(&mut self, k: K, v: V, size: NonZeroUsize)
pub fn insert_sized(&mut self, k: K, v: V, size: NonZeroUsize)
Insert an item to the cache, with an associated weight/size factor. See also insert
sourcepub fn remove(&mut self, k: K)
pub fn remove(&mut self, k: K)
Remove this value from the thread local cache IE mask from from being returned until this thread performs an insert. This item is marked as clean IE you have synced it to whatever associated store exists.
sourcepub fn insert_dirty(&mut self, k: K, v: V)
pub fn insert_dirty(&mut self, k: K, v: V)
Add a value to the cache. This may be because you have had a cache miss and
now wish to include in the thread local storage, or because you have written
a new value and want it to be submitted for caching. This item is marked as
dirty, because you have not synced it. You MUST call iter_mut_mark_clean before calling
commit
on this transaction, or a panic will occur.
sourcepub fn insert_dirty_sized(&mut self, k: K, v: V, size: NonZeroUsize)
pub fn insert_dirty_sized(&mut self, k: K, v: V, size: NonZeroUsize)
Insert a dirty item to the cache, with an associated weight/size factor. See also insert_dirty
sourcepub fn remove_dirty(&mut self, k: K)
pub fn remove_dirty(&mut self, k: K)
Remove this value from the thread local cache IE mask from from being
returned until this thread performs an insert. This item is marked as
dirty, because you have not synced it. You MUST call iter_mut_mark_clean before calling
commit
on this transaction, or a panic will occur.
sourcepub fn iter_dirty(&self) -> impl Iterator<Item = (&K, Option<&V>)>
pub fn iter_dirty(&self) -> impl Iterator<Item = (&K, Option<&V>)>
Yields an iterator over all values that are currently dirty. As the iterator progresses, items will NOT be marked clean. This allows you to examine any currently dirty items in the cache.
sourcepub fn iter_mut_dirty(&mut self) -> impl Iterator<Item = (&K, Option<&mut V>)>
pub fn iter_mut_dirty(&mut self) -> impl Iterator<Item = (&K, Option<&mut V>)>
Yields a mutable iterator over all values that are currently dirty. As the iterator progresses, items will NOT be marked clean. This allows you to modify and change any currently dirty items as required.
sourcepub fn iter_mut_mark_clean(
&mut self,
) -> impl Iterator<Item = (&K, Option<&mut V>)>
pub fn iter_mut_mark_clean( &mut self, ) -> impl Iterator<Item = (&K, Option<&mut V>)>
Yields an iterator over all values that are currently dirty. As the iterator
progresses, items will be marked clean. This is where you should sync dirty
cache content to your associated store. The iterator is K, Option
sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
Yield an iterator over all currently live and valid cache items.