A cache that uses a simple LRU (least-recently-used) replacement scheme.
sealed class
|
LruCache
|
with
|
<TId>
|
||
implements
|
ICache<TId>
|
The capacity of this cache.
public
property
|
Capacity
{
get
}
|
||
type
|
int32
|
||
value
|
|
The maximum number of entries this cache can hold. | |
implements
|
ICacheBase.Capacity
|
The page ID value that represents non-existent mappings.
public
property
|
InvalidId
{
get
}
|
||
type
|
TId
|
||
value
|
The invalid page ID value. | ||
implements
|
ICacheBase.InvalidId
|
Returns the index of the oldest cache page.
public
property
|
Oldest
{
get
}
|
||
type
|
int32
|
||
value
|
|
Index
of
the
least-recently
used
cache
page
or
-1
if
all
pages
are
unused.
|
|
implements
|
ICacheBase.Oldest
|
Creates a new instance of LruCache.
public
constructor
|
LruCache
(int32 capacity,
ICacheCallback<TId> callback = null,
TId invalidId = default(TId),
EqualsDelegate<TId> equals = null,
HashCodeDelegate<TId> hashCode = null)
|
||
params
|
capacity
|
[>0]
|
The cache capacity. |
callback
|
Optional
cache
callback.
If
null ,
using
the
Partial
will
have
no
effect.
Defaults
to
null .
|
||
invalidId
|
The page ID value that represents an invalid page ID. Unused cached slots will be set to this value. | ||
equals
|
The
equality
delegate.
Defaults
to
null . |
||
hashCode
|
Optional
hash
code
delegate.
Defaults
to
null . |
Evicts all pages from the cache.
public
method
|
EvictAll
()
|
||
implements
|
ICacheBase.EvictAll
|
Evicts the given page from the cache.
public
method
|
EvictId
(TId pageId)
|
||
params
|
pageId
|
The cache page ID. | |
implements
|
ICacheBase.EvictId
|
Remarks:
Requesting the given page later will cause a cache miss.
Evicts the given page from the cache.
public
method
|
EvictIndex
(int32 pageIndex)
|
||
params
|
pageIndex
|
[0..Capacity-1]
|
The cache page index. |
implements
|
ICacheBase.EvictIndex
|
Remarks:
Requesting the given page later will cause a cache miss.
Fetches a page from the cache, loading it if necessary.
public
method
|
Fetch
(TId pageId)
|
||
type
|
int32
|
||
params
|
pageId
|
The page ID. | |
returns
|
|
||
implements
|
ICacheBase.Fetch
|
Fetches a page from the cache, loading it if necessary.
public
method
|
Fetch
(TId pageId,
PageLoadFlags loadFlags,
bool keepLocked)
|
||
type
|
int32
|
||
params
|
pageId
|
The page ID. | |
loadFlags
|
The flags that determine how to load the cache page. When set to Manual, cache page loading will not be performed. The calling code must load the cache page in this case. | ||
keepLocked
|
Keep the cache page in locked state after fetching it (see LockPage)? | ||
returns
|
|
||
implements
|
ICache.Fetch
|
Remarks:
When this method returns, all necessary calls to CachePageChoose and CachePageData will have been done.
Returns the page ID of the given page.
public
method
|
GetId
(int32 pageIndex)
|
||
type
|
TId
|
||
params
|
pageIndex
|
[0..Capacity-1]
|
The page index. |
returns
|
The page ID. | ||
implements
|
ICacheBase.GetId
|
Remarks:
The state of the cache is not modified by this method.
Returns the cache page index of the given page.
public
method
|
GetIndex
(TId pageId,
bool hitPage = false)
|
||
type
|
int32
|
||
params
|
pageId
|
The page ID. | |
hitPage
|
Update state of the cache by hitting the page if it exists? | ||
returns
|
|
The
cache
page
index
or
-1 . |
|
implements
|
ICacheBase.GetIndex
|
Remarks:
The
state
of
the
cache
is
not
modified
by
this
method
if
hitPage
is
false
.
Is the given cache page locked?
public
method
|
IsPageLocked
(int32 pageIndex)
|
||
type
|
bool
|
||
params
|
pageIndex
|
[0..Capacity-1]
|
Index of page to unlock. |
returns
|
true
if
the
cache
page
is
locked,
false
if
not. |
||
implements
|
ICache.IsPageLocked
|
See also:
ICache.LockPageHas the given page been partially loaded?
public
method
|
IsPartial
(int32 pageIndex)
|
||
type
|
bool
|
||
params
|
pageIndex
|
[0..Capacity-1]
|
The page index. |
returns
|
true
if
the
given
page
has
been
loaded
partially,
false
if
the
page
is
either
fully
loaded
or
non-existent.
|
||
implements
|
ICache.IsPartial
|
See also:
PageLoadFlags.PartialLocks a cache page so that it will not be evicted from the cache by future calls.
public
method
|
LockPage
(int32 pageIndex)
|
||
params
|
pageIndex
|
[0..Capacity-1]
|
Index of page to lock. |
implements
|
ICache.LockPage
|
See also:
ICache.UnlockPageUnlocks a previously locked cache page.
public
method
|
UnlockPage
(int32 pageIndex)
|
||
params
|
pageIndex
|
[0..Capacity-1]
|
Index of page to unlock. |
implements
|
ICache.UnlockPage
|
See also:
ICache.LockPageThe given cache page has been used.
public
method
|
Use
(int32 pageIndex)
|
||
params
|
pageIndex
|
[0..Capacity-1]
|
The page index. |
implements
|
ICacheBase.Use
|
Remarks:
Use this method to avoid specific pages to get evicted from the cache too soon.