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>

source

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)

source

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.

source

pub fn get<Q>(&mut self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

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.

source

pub fn get_mut<Q>(&mut self, k: &Q, make_dirty: bool) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

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

source

pub fn contains_key<Q>(&mut self, k: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Determine if this cache contains the following key.

source

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.

source

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

source

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.

source

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.

source

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

source

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.

source

pub fn is_dirty(&self) -> bool

Determines if dirty elements exist in this cache or not.

source

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.

source

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.

source

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, where the Option indicates if the item has been remove (None) or is updated (Some).

source

pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>

Yield an iterator over all currently live and valid cache items.

source

pub fn iter_rec(&self) -> impl Iterator<Item = &K>

Yield an iterator over all currently live and valid items in the recent access list.

source

pub fn iter_freq(&self) -> impl Iterator<Item = &K>

Yield an iterator over all currently live and valid items in the frequent access list.

Auto Trait Implementations§

§

impl<'a, K, V, S> !Freeze for ARCacheWriteTxn<'a, K, V, S>

§

impl<'a, K, V, S> !RefUnwindSafe for ARCacheWriteTxn<'a, K, V, S>

§

impl<'a, K, V, S> !Send for ARCacheWriteTxn<'a, K, V, S>

§

impl<'a, K, V, S> !Sync for ARCacheWriteTxn<'a, K, V, S>

§

impl<'a, K, V, S> Unpin for ARCacheWriteTxn<'a, K, V, S>
where S: Unpin, K: Unpin, V: Unpin,

§

impl<'a, K, V, S> UnwindSafe for ARCacheWriteTxn<'a, K, V, S>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more