pub trait PageCache {
// Required methods
fn cache_size(&mut self, cache_size: usize);
fn page_count(&mut self) -> usize;
fn fetch(
&mut self,
key: usize,
create_flag: CreateFlag,
) -> Option<&mut PageWithMetadata>;
fn unpin(&mut self, key: usize, discard: DiscardStrategy);
fn rekey(&mut self, old_key: usize, new_key: usize);
fn truncate(&mut self, limit: usize);
fn destroy(&mut self);
fn shrink(&mut self);
}
Required Methods§
Sourcefn cache_size(&mut self, cache_size: usize)
fn cache_size(&mut self, cache_size: usize)
The cache_size
method may be called at any time by SQLite to set the suggested maximum
cache-size (number of pages stored by) the cache instance passed as the first argument.
This is the value configured using the SQLite “PRAGMA cache_size” command. It
is advisory only.
Sourcefn page_count(&mut self) -> usize
fn page_count(&mut self) -> usize
The page_count
method must return the number of pages currently stored in the cache, both
pinned and unpinned.
Sourcefn fetch(
&mut self,
key: usize,
create_flag: CreateFlag,
) -> Option<&mut PageWithMetadata>
fn fetch( &mut self, key: usize, create_flag: CreateFlag, ) -> Option<&mut PageWithMetadata>
The fetch
method locates a page in the cache or None (see CreateFlag for detail on cache
miss).
The page to be fetched is determined by the key
. The minimum key value is 1. After it has
been retrieved using fetch
, the page is considered to be “pinned”.
SQLite will normally invoke fetch
with a createFlag of NoAllocation or
AllocateIfConvenient. SQLite will only use a createFlag of Allocate after a prior call with
a createFlag of AllocateIfConvenient failed. In between the fetch
calls, SQLite may
attempt to unpin one or more cache pages by spilling the content of pinned pages to disk
and synching the operating system disk cache.
Sourcefn unpin(&mut self, key: usize, discard: DiscardStrategy)
fn unpin(&mut self, key: usize, discard: DiscardStrategy)
unpin
is called by SQLite with a pointer to a currently pinned page.
The page cache implementation may choose to evict unpinned pages at any time.
Sourcefn rekey(&mut self, old_key: usize, new_key: usize)
fn rekey(&mut self, old_key: usize, new_key: usize)
The rekey
method is used to change the key value associated with the page passed as the
second argument. If the cache previously contains an entry associated with new_key
, it must
be discarded. Any prior cache entry associated with new_key
is guaranteed not to be pinned.
Sourcefn truncate(&mut self, limit: usize)
fn truncate(&mut self, limit: usize)
When SQLite calls the truncate
method, the cache must discard all existing cache entries
with page numbers (keys) greater than or equal to the value of the limit
parameter passed
to truncate
. If any of these pages are pinned, they are implicitly unpinned, meaning
that they can be safely discarded.