Struct git_odb::Cache

source ·
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§

source§

impl Cache<Handle<Rc<Store>>>

source

pub fn into_arc(self) -> Result<Cache<Handle<Arc<Store>>>>

Convert this cache’s handle into one that keeps its store in an arc. This creates an entirely new store, so should be done early to avoid unnecessary work (and mappings).

source§

impl Cache<Handle<Arc<Store>>>

source

pub fn into_arc(self) -> Result<Cache<Handle<Arc<Store>>>>

No op, as we are containing an arc handle already.

source§

impl<S> Cache<S>

source

pub fn into_inner(self) -> S

Dissolve this instance, discard all caches, and return the inner implementation.

source

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.

source

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.

source

pub fn set_pack_cache( &mut self, create: impl Fn() -> Box<PackCache> + Send + Sync + 'static )

Set the pack cache constructor on this instance.

source

pub fn set_object_cache( &mut self, create: impl Fn() -> Box<ObjectCache> + Send + Sync + 'static )

Set the object cache constructor on this instance.

source

pub fn has_object_cache(&self) -> bool

Return true if an object cache is present.

source

pub fn has_pack_cache(&self) -> bool

Return true if a pack cache is present.

source

pub fn unset_pack_cache(&mut self)

Remove the current pack cache as well as its constructor from this instance.

source

pub fn unset_object_cache(&mut self)

Remove the current object cache as well as its constructor from this instance.

Trait Implementations§

source§

impl<S: Clone> Clone for Cache<S>

source§

fn clone(&self) -> Self

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<S> Deref for Cache<S>

§

type Target = S

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<S> DerefMut for Cache<S>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<S> Find for Cache<S>where S: Find,

§

type Error = <S as Find>::Error

The error returned by try_find()
source§

fn contains(&self, id: impl AsRef<oid>) -> bool

Returns true if the object exists in the database.
source§

fn try_find<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8> ) -> Result<Option<Data<'a>>, Self::Error>

Find an object matching id in the database while placing its raw, possibly encoded data into buffer. Read more
source§

impl<S> Find for Cache<S>where S: Find,

§

type Error = <S as Find>::Error

The error returned by try_find()
source§

fn contains(&self, id: impl AsRef<oid>) -> bool

Returns true if the object exists in the database.
source§

fn try_find<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8> ) -> Result<Option<(Data<'a>, Option<Location>)>, Self::Error>

Find an object matching id in the database while placing its raw, decoded 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 more
source§

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>

Like 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 more
source§

fn location_by_oid( &self, id: impl AsRef<oid>, buf: &mut Vec<u8> ) -> Option<Location>

Find the packs location where an object with id can be found in the database, or None if there is no pack holding the object. Read more
source§

fn pack_offsets_and_oid(&self, pack_id: u32) -> Option<Vec<(u64, ObjectId)>>

Obtain a vector of all offsets, in index order, along with their object id.
source§

fn entry_by_location(&self, location: &Location) -> Option<Entry>

Return the find::Entry for location if it is backed by a pack. Read more
source§

impl<S> From<S> for Cache<S>where S: Find,

source§

fn from(store: S) -> Self

Converts to this type from the input type.
source§

impl<S> Header for Cache<S>where S: Header,

§

type Error = <S as Header>::Error

The error returned by try_header().
source§

fn try_header(&self, id: impl AsRef<oid>) -> Result<Option<Header>, Self::Error>

Try to read the header of the object associated with id or return None if it could not be found.
source§

impl<S> Write for Cache<S>where S: Write,

§

type Error = <S as Write>::Error

The error type used for all trait methods. Read more
source§

fn write_stream( &self, kind: Kind, size: u64, from: impl Read ) -> Result<ObjectId, Self::Error>

As write, but takes an input stream. This is commonly used for writing blobs directly without reading them to memory first.
source§

fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error>

Write objects using the intrinsic kind of hash into the database, returning id to reference it in subsequent reads.
source§

fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, Self::Error>

As write, but takes an object kind along with its encoded bytes.

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§

source§

impl<T, A, P> Access<T> for Pwhere A: Access<T> + ?Sized, P: Deref<Target = A>,

§

type Guard = <A as Access<T>>::Guard

A guard object containing the value and keeping it alive. Read more
source§

fn load(&self) -> <P as Access<T>>::Guard

The loading method. Read more
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, A> DynAccess<T> for Awhere A: Access<T>, <A as Access<T>>::Guard: 'static,

source§

fn load(&self) -> DynGuard<T>

The equivalent of Access::load.
source§

impl<T> FindExt for Twhere T: Find,

source§

fn find<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8, Global> ) -> Result<(Data<'a>, Option<Location>), Error<Self::Error>>

Like try_find(…), but flattens the Result<Option<_>> into a single Result making a non-existing object an error.
source§

fn find_commit<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8, Global> ) -> Result<(CommitRef<'a>, Option<Location>), Error<Self::Error>>

Like find(…), but flattens the Result<Option<_>> into a single Result making a non-existing object an error while returning the desired object type.
source§

fn find_tree<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8, Global> ) -> Result<(TreeRef<'a>, Option<Location>), Error<Self::Error>>

Like find(…), but flattens the Result<Option<_>> into a single Result making a non-existing object an error while returning the desired object type.
source§

fn find_tag<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8, Global> ) -> Result<(TagRef<'a>, Option<Location>), Error<Self::Error>>

Like find(…), but flattens the Result<Option<_>> into a single Result making a non-existing object an error while returning the desired object type.
source§

fn find_blob<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8, Global> ) -> Result<(BlobRef<'a>, Option<Location>), Error<Self::Error>>

Like find(…), but flattens the Result<Option<_>> into a single Result making a non-existing object an error while returning the desired object type.
source§

fn find_commit_iter<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8, Global> ) -> Result<(CommitRefIter<'a>, Option<Location>), Error<Self::Error>>

Like find(…), but flattens the Result<Option<_>> into a single Result making a non-existing object an error while returning the desired iterator type.
source§

fn find_tree_iter<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8, Global> ) -> Result<(TreeRefIter<'a>, Option<Location>), Error<Self::Error>>

Like find(…), but flattens the Result<Option<_>> into a single Result making a non-existing object an error while returning the desired iterator type.
source§

fn find_tag_iter<'a>( &self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8, Global> ) -> Result<(TagRefIter<'a>, Option<Location>), Error<Self::Error>>

Like find(…), but flattens the Result<Option<_>> into a single Result making a non-existing object an error while returning the desired iterator type.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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<T> Formattable for Twhere T: Deref, <T as Deref>::Target: Formattable,

§

impl<T> Parsable for Twhere T: Deref, <T as Deref>::Target: Parsable,