Struct odilia_cache::Cache

source ·
pub struct Cache {
    pub by_id: Arc<DashMap<AccessiblePrimitive, Arc<RwLock<CacheItem>>, FxBuildHasher>>,
    pub connection: Connection,
}
Expand description

An internal cache used within Odilia.

This contains (mostly) all accessibles in the entire accessibility tree, and they are referenced by their IDs. If you are having issues with incorrect or invalid accessibles trying to be accessed, this is code is probably the issue.

Fields§

§by_id: Arc<DashMap<AccessiblePrimitive, Arc<RwLock<CacheItem>>, FxBuildHasher>>§connection: Connection

Implementations§

source§

impl Cache

source

pub fn new(conn: Connection) -> Self

create a new, fresh cache

source

pub fn add(&self, cache_item: CacheItem)

add a single new item to the cache. Note that this will empty the bucket before inserting the CacheItem into the cache (this is so there is never two items with the same ID stored in the cache at the same time).

source

pub fn add_ref( &self, id: AccessiblePrimitive, cache_item: Arc<RwLock<CacheItem>> )

source

pub fn remove(&self, id: &AccessiblePrimitive)

Remove a single cache item

source

pub fn get_ref( &self, id: &AccessiblePrimitive ) -> Option<Arc<RwLock<CacheItem>>>

Get a single item (mutable via lock) from the cache.

source

pub fn get(&self, id: &AccessiblePrimitive) -> Option<CacheItem>

Get a single item from the cache.

This will allow you to get the item without holding any locks to it, at the cost of (1) a clone and (2) no guarantees that the data is kept up-to-date.

source

pub fn get_all(&self, ids: &[AccessiblePrimitive]) -> Vec<Option<CacheItem>>

get a many items from the cache; this only creates one read handle (note that this will copy all data you would like to access)

source

pub fn add_all(&self, cache_items: Vec<CacheItem>)

Bulk add many items to the cache; only one accessible should ever be associated with an id.

source

pub fn remove_all(&self, ids: Vec<AccessiblePrimitive>)

Bulk remove all ids in the cache; this only refreshes the cache after removing all items.

source

pub fn modify_item<F>(&self, id: &AccessiblePrimitive, modify: F) -> boolwhere F: FnOnce(&mut CacheItem),

Edit a mutable CacheItem. Returns true if the update was successful.

Note: an exclusive lock for the given cache item will be placed for the entire length of the passed function, so try to avoid any compute in it.

source

pub async fn get_or_create( &self, accessible: &AccessibleProxy<'_>, cache: Weak<Self> ) -> OdiliaResult<CacheItem>

Get a single item from the cache (note that this copies some integers to a new struct). If the CacheItem is not found, create one, add it to the cache, and return it.

Trait Implementations§

source§

impl Clone for Cache

source§

fn clone(&self) -> Cache

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Cache

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Cache

§

impl Send for Cache

§

impl Sync for Cache

§

impl Unpin for Cache

§

impl !UnwindSafe for Cache

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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