pub trait EvictionPolicy {
type Error: Error;
// Required methods
fn evict(&self) -> Option<FrameId>;
fn peek(&self) -> Option<FrameId>;
fn touch(&self, id: FrameId) -> Result<(), Self::Error>;
fn touch_with<T: AccessType>(
&self,
id: FrameId,
access_type: T,
) -> Result<(), Self::Error>;
fn pin(&self, id: FrameId) -> Result<(), Self::Error>;
fn unpin(&self, id: FrameId) -> Result<(), Self::Error>;
fn remove(&self, id: FrameId) -> Result<(), Self::Error>;
fn capacity(&self) -> usize;
fn size(&self) -> usize;
}Expand description
Cache frame eviction policy.
Defines an interface for interacting with different cache eviction strategies. At its core, it provides methods for logging data access, managing metadata, and eventually locating the next frame to evict.
Required Associated Types§
Required Methods§
Sourcefn evict(&self) -> Option<FrameId>
fn evict(&self) -> Option<FrameId>
Find the next frame to be evicted and evict it.
Only non-pinned frames are candidates for eviction.
Use EvictionPolicy::pin to pin frames.
Successful eviction of a frame decreases the list size of non-pinned frames and potentially cleans the frame’s access history.
Sourcefn peek(&self) -> Option<FrameId>
fn peek(&self) -> Option<FrameId>
Peek into the next frame to be evicted.
This function does not remove the frame from the list of non-pinned frames.
Sourcefn touch(&self, id: FrameId) -> Result<(), Self::Error>
fn touch(&self, id: FrameId) -> Result<(), Self::Error>
Notifies the policy manager that a page controlled by the frame has been referenced/accessed.
This normally updates the access history of a frame using the current timestamp.
Sourcefn touch_with<T: AccessType>(
&self,
id: FrameId,
access_type: T,
) -> Result<(), Self::Error>
fn touch_with<T: AccessType>( &self, id: FrameId, access_type: T, ) -> Result<(), Self::Error>
Notifies the policy manager that a page controlled by the frame has been referenced/accessed. In addition to mere occurrence of access, this method also logs the type of the access.
Sourcefn pin(&self, id: FrameId) -> Result<(), Self::Error>
fn pin(&self, id: FrameId) -> Result<(), Self::Error>
Pin a frame, marking it as non-evictable.
If the frame is already pinned, nothing happens.
Sourcefn unpin(&self, id: FrameId) -> Result<(), Self::Error>
fn unpin(&self, id: FrameId) -> Result<(), Self::Error>
Unpin a frame, marking it as evictable.
If the frame is already unpinned, nothing happens.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.