pub struct ClockCache { /* private fields */ }
Expand description

A cache for storing arbitrary length data, the cache size can grow and shrink with page granularity

There is only one major API: probe_entry(), which either returns an empty entry or an entry that should be evicted (to accommodate the new value).

Remove/add segment can only be invoked by one thread at a time.

Implementations

only one thread at any time should call this function

Safety

The ptr must be valid and at least SEGMENT_SIZE (default 4096) bytes long.

The only safe and stable way to get a ptr is to call Segment::alloc().

The caller need to iterate all the entries in the segment and evict them As long as the lock guard is held, not other thread can promote entry to this segment

Returns None when all segments in the cache are removed

source

pub fn probe_entry(&self) -> Option<&EntryMeta>

Returns whether we find a cached location. If yes, returns the cached location.

The caller need to check the reserved bit, if not set, this entry need to be evicted to the storage

Unless the reserved bit is set (the entry is empty), it is the caller’s responsibility to serialize the concurrent read/write.

There are two cases this function may return None:

  1. The cache is empty (due to remove_segment)
  2. The all the entries are referenced within the probe_len (default to 16)

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.