pub struct SqliteCache { /* private fields */ }Expand description
The SQLite cache. Cheap to clone (clones share one connection).
Implementations§
Source§impl SqliteCache
impl SqliteCache
Sourcepub fn index_restaurants_at(
&self,
rows: &[RestaurantRow],
seen_from: Option<(f64, f64)>,
now: i64,
) -> Result<(), DbError>
pub fn index_restaurants_at( &self, rows: &[RestaurantRow], seen_from: Option<(f64, f64)>, now: i64, ) -> Result<(), DbError>
Upsert restaurants seen in a list response. seen_from is the
delivery location of the request; when given, each row’s distance /
ETA / fee are also recorded for that location.
Sourcepub fn index_items_at(&self, items: &[ItemRow], now: i64) -> Result<(), DbError>
pub fn index_items_at(&self, items: &[ItemRow], now: i64) -> Result<(), DbError>
Upsert individual items (e.g. dish hits in search results), keeping any category already known.
Store a full menu: the restaurant, its categories (replacing the old ones) and items; items no longer on the menu are removed.
Sourcepub fn search_restaurants(
&self,
q: &RestaurantQuery,
) -> Result<Vec<RestaurantHit>, DbError>
pub fn search_restaurants( &self, q: &RestaurantQuery, ) -> Result<Vec<RestaurantHit>, DbError>
Query restaurants in the catalog.
Sourcepub fn search_items(&self, q: &ItemQuery) -> Result<Vec<ItemHit>, DbError>
pub fn search_items(&self, q: &ItemQuery) -> Result<Vec<ItemHit>, DbError>
Query menu items in the catalog.
Sourcepub fn restaurant(&self, id: &str) -> Result<Option<RestaurantHit>, DbError>
pub fn restaurant(&self, id: &str) -> Result<Option<RestaurantHit>, DbError>
One restaurant by id.
Source§impl SqliteCache
impl SqliteCache
Sourcepub fn cached_image_at(&self, url: &str, now: i64) -> Option<CachedImage>
pub fn cached_image_at(&self, url: &str, now: i64) -> Option<CachedImage>
The cached file for url, if present (and still on disk). Marks it
recently used.
Sourcepub fn store_image_at(
&self,
url: &str,
bytes: &[u8],
content_type: &str,
now: i64,
) -> Result<CachedImage, DbError>
pub fn store_image_at( &self, url: &str, bytes: &[u8], content_type: &str, now: i64, ) -> Result<CachedImage, DbError>
Store downloaded image bytes for url (dedupes by content hash), then
evict over the size cap.
Source§impl SqliteCache
impl SqliteCache
Sourcepub fn new(root: impl Into<PathBuf>, config: CacheConfig) -> Self
pub fn new(root: impl Into<PathBuf>, config: CacheConfig) -> Self
pub fn db_path(&self) -> PathBuf
pub fn config(&self) -> &CacheConfig
pub fn ttl(&self, kind: CacheKind) -> u64
pub fn stats(&self) -> Result<CacheStats>
Sourcepub fn clear_all(&self) -> Result<ClearReport>
pub fn clear_all(&self) -> Result<ClearReport>
Remove everything: responses, catalog rows and image files.
Sourcepub fn prune(&self) -> Result<PruneReport>
pub fn prune(&self) -> Result<PruneReport>
Housekeeping: drop expired responses, catalog rows older than
index_max_age_days, and evict images over image_max_mb (LRU), then
compact the database.
Trait Implementations§
Source§impl Cache for SqliteCache
impl Cache for SqliteCache
Source§fn get_entry<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 CacheKey,
) -> Pin<Box<dyn Future<Output = Result<Option<CacheEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_entry<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 CacheKey,
) -> Pin<Box<dyn Future<Output = Result<Option<CacheEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
key (expired or not), if any.Source§fn put_entry<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 CacheKey,
entry: &'life2 CacheEntry,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn put_entry<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 CacheKey,
entry: &'life2 CacheEntry,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
key.Source§fn index_restaurants<'life0, 'life1, 'async_trait>(
&'life0 self,
rows: &'life1 [RestaurantRow],
seen_from: Option<(f64, f64)>,
now: i64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn index_restaurants<'life0, 'life1, 'async_trait>(
&'life0 self,
rows: &'life1 [RestaurantRow],
seen_from: Option<(f64, f64)>,
now: i64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
seen_from is the
delivery location of the request; when given, each row’s distance /
ETA / fee are also recorded for that location.Source§fn index_items<'life0, 'life1, 'async_trait>(
&'life0 self,
items: &'life1 [ItemRow],
now: i64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn index_items<'life0, 'life1, 'async_trait>(
&'life0 self,
items: &'life1 [ItemRow],
now: i64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn search_restaurants<'life0, 'life1, 'async_trait>(
&'life0 self,
q: &'life1 RestaurantQuery,
) -> Pin<Box<dyn Future<Output = Result<Vec<RestaurantHit>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search_restaurants<'life0, 'life1, 'async_trait>(
&'life0 self,
q: &'life1 RestaurantQuery,
) -> Pin<Box<dyn Future<Output = Result<Vec<RestaurantHit>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn search_items<'life0, 'life1, 'async_trait>(
&'life0 self,
q: &'life1 ItemQuery,
) -> Pin<Box<dyn Future<Output = Result<Vec<ItemHit>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search_items<'life0, 'life1, 'async_trait>(
&'life0 self,
q: &'life1 ItemQuery,
) -> Pin<Box<dyn Future<Output = Result<Vec<ItemHit>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn restaurant<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<RestaurantHit>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn restaurant<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<RestaurantHit>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn image<'life0, 'life1, 'async_trait>(
&'life0 self,
url: &'life1 str,
now: i64,
) -> Pin<Box<dyn Future<Output = Result<Option<CachedImage>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn image<'life0, 'life1, 'async_trait>(
&'life0 self,
url: &'life1 str,
now: i64,
) -> Pin<Box<dyn Future<Output = Result<Option<CachedImage>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
url, marking it recently used.Source§fn put_image<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
url: &'life1 str,
bytes: &'life2 [u8],
content_type: &'life3 str,
now: i64,
) -> Pin<Box<dyn Future<Output = Result<CachedImage>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn put_image<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
url: &'life1 str,
bytes: &'life2 [u8],
content_type: &'life3 str,
now: i64,
) -> Pin<Box<dyn Future<Output = Result<CachedImage>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
url.