pub struct Cache<S> { /* private fields */ }
Expand description
A way to access objects along with pre-configured thread-local caches for packed base objects as well as objects themselves.
By default, no cache will be used.
Implementations
sourceimpl<S> Cache<S>
impl<S> Cache<S>
sourcepub fn into_inner(self) -> S
pub fn into_inner(self) -> S
Dissolve this instance, discard all caches, and return the inner implementation.
sourcepub fn with_pack_cache(
self,
create: impl Fn() -> Box<PackCache> + Send + Sync + 'static
) -> Self
pub fn with_pack_cache(
self,
create: impl Fn() -> Box<PackCache> + Send + Sync + 'static
) -> Self
Use this methods directly after creating a new instance to add a constructor for pack caches.
These are used to speed up decoding objects which are located in packs, reducing long delta chains by storing their intermediate results.
sourcepub fn with_object_cache(
self,
create: impl Fn() -> Box<ObjectCache> + Send + Sync + 'static
) -> Self
pub fn with_object_cache(
self,
create: impl Fn() -> Box<ObjectCache> + Send + Sync + 'static
) -> Self
Use this methods directly after creating a new instance to add a constructor for object caches.
Only use this kind of cache if the same objects are repeatedly accessed for great speedups, usually during diffing of trees.
sourcepub fn set_pack_cache(
&mut self,
create: impl Fn() -> Box<PackCache> + Send + Sync + 'static
)
pub fn set_pack_cache(
&mut self,
create: impl Fn() -> Box<PackCache> + Send + Sync + 'static
)
Set the pack cache constructor on this instance.
sourcepub fn set_object_cache(
&mut self,
create: impl Fn() -> Box<ObjectCache> + Send + Sync + 'static
)
pub fn set_object_cache(
&mut self,
create: impl Fn() -> Box<ObjectCache> + Send + Sync + 'static
)
Set the object cache constructor on this instance.
sourcepub fn has_object_cache(&self) -> bool
pub fn has_object_cache(&self) -> bool
Return true if an object cache is present.
sourcepub fn has_pack_cache(&self) -> bool
pub fn has_pack_cache(&self) -> bool
Return true if a pack cache is present.
sourcepub fn unset_pack_cache(&mut self)
pub fn unset_pack_cache(&mut self)
Remove the current pack cache as well as its constructor from this instance.
sourcepub fn unset_object_cache(&mut self)
pub fn unset_object_cache(&mut self)
Remove the current object cache as well as its constructor from this instance.
Trait Implementations
sourceimpl<S> Find for Cache<S>where
S: Find,
impl<S> Find for Cache<S>where
S: Find,
sourceimpl<S> Find for Cache<S>where
S: Find,
impl<S> Find for Cache<S>where
S: Find,
type Error = <S as Find>::Error
type Error = <S as Find>::Error
try_find()
sourcefn contains(&self, id: impl AsRef<oid>) -> bool
fn contains(&self, id: impl AsRef<oid>) -> bool
sourcefn try_find<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<Option<(Data<'a>, Option<Location>)>, Self::Error>
fn try_find<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<Option<(Data<'a>, Option<Location>)>, Self::Error>
id
in the database while placing its raw, undecoded data into buffer
.
A pack_cache
can be used to speed up subsequent lookups, set it to crate::cache::Never
if the
workload isn’t suitable for caching. Read moresourcefn try_find_cached<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>,
pack_cache: &mut impl DecodeEntry
) -> Result<Option<(Data<'a>, Option<Location>)>, Self::Error>
fn try_find_cached<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>,
pack_cache: &mut impl DecodeEntry
) -> Result<Option<(Data<'a>, Option<Location>)>, Self::Error>
Find::try_find()
, but with support for controlling the pack cache.
A pack_cache
can be used to speed up subsequent lookups, set it to crate::cache::Never
if the
workload isn’t suitable for caching. Read moresourcefn location_by_oid(
&self,
id: impl AsRef<oid>,
buf: &mut Vec<u8>
) -> Option<Location>
fn location_by_oid(
&self,
id: impl AsRef<oid>,
buf: &mut Vec<u8>
) -> Option<Location>
id
can be found in the database, or None
if there is no pack
holding the object. Read moresourcefn pack_offsets_and_oid(&self, pack_id: u32) -> Option<Vec<(u64, ObjectId)>>
fn pack_offsets_and_oid(&self, pack_id: u32) -> Option<Vec<(u64, ObjectId)>>
sourcefn entry_by_location(&self, location: &Location) -> Option<Entry>
fn entry_by_location(&self, location: &Location) -> Option<Entry>
Auto Trait Implementations
impl<S> !RefUnwindSafe for Cache<S>
impl<S> Send for Cache<S>where
S: Send,
impl<S> !Sync for Cache<S>
impl<S> Unpin for Cache<S>where
S: Unpin,
impl<S> !UnwindSafe for Cache<S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T, A> DynAccess<T> for Awhere
A: Access<T>,
<A as Access<T>>::Guard: 'static,
impl<T, A> DynAccess<T> for Awhere
A: Access<T>,
<A as Access<T>>::Guard: 'static,
sourcefn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load
.sourceimpl<T> FindExt for Twhere
T: Find,
impl<T> FindExt for Twhere
T: Find,
sourcefn find<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8, Global>
) -> Result<(Data<'a>, Option<Location>), Error<Self::Error>>
fn find<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8, Global>
) -> Result<(Data<'a>, Option<Location>), Error<Self::Error>>
try_find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error.