pub struct DataLoader<T, C = NoCache> { /* private fields */ }
Expand description
Data loader.
Reference: https://github.com/facebook/dataloader
Implementations§
Source§impl<T> DataLoader<T, NoCache>
impl<T> DataLoader<T, NoCache>
Source§impl<T, C: CacheFactory> DataLoader<T, C>
impl<T, C: CacheFactory> DataLoader<T, C>
Sourcepub fn with_cache<S, R>(loader: T, spawner: S, cache_factory: C) -> Self
pub fn with_cache<S, R>(loader: T, spawner: S, cache_factory: C) -> Self
Use Loader
to create a DataLoader
with a cache factory.
Sourcepub fn delay(self, delay: Duration) -> Self
pub fn delay(self, delay: Duration) -> Self
Specify the delay time for loading data, the default is 1ms
.
Sourcepub fn max_batch_size(self, max_batch_size: usize) -> Self
pub fn max_batch_size(self, max_batch_size: usize) -> Self
pub fn Specify the max batch size for loading data, the default is
1000
.
If the keys waiting to be loaded reach the threshold, they are loaded immediately.
Sourcepub fn enable_all_cache(&self, enable: bool)
pub fn enable_all_cache(&self, enable: bool)
Enable/Disable cache of all loaders.
Sourcepub fn enable_cache<K, V>(&self, enable: bool)
pub fn enable_cache<K, V>(&self, enable: bool)
Enable/Disable cache of specified loader.
Sourcepub async fn load_one<K, V>(&self, key: K) -> Result<Option<V>, T::Error>
pub async fn load_one<K, V>(&self, key: K) -> Result<Option<V>, T::Error>
Use this DataLoader
load a data.
Sourcepub async fn load_many<K, V, I>(
&self,
keys: I,
) -> Result<HashMap<K, V>, T::Error>
pub async fn load_many<K, V, I>( &self, keys: I, ) -> Result<HashMap<K, V>, T::Error>
Use this DataLoader
to load some data.
Sourcepub async fn feed_many<K, V, I>(&self, values: I)
pub async fn feed_many<K, V, I>(&self, values: I)
Feed some data into the cache.
**NOTE: If the cache type is NoCache
, this function will not take
effect. **
Sourcepub async fn feed_one<K, V>(&self, key: K, value: V)
pub async fn feed_one<K, V>(&self, key: K, value: V)
Feed some data into the cache.
**NOTE: If the cache type is NoCache
, this function will not take
effect. **
Auto Trait Implementations§
impl<T, C = NoCache> !Freeze for DataLoader<T, C>
impl<T, C = NoCache> !RefUnwindSafe for DataLoader<T, C>
impl<T, C> Send for DataLoader<T, C>
impl<T, C> Sync for DataLoader<T, C>
impl<T, C> Unpin for DataLoader<T, C>where
C: Unpin,
impl<T, C = NoCache> !UnwindSafe for DataLoader<T, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more