P
- Page typepublic class LRUCache<P extends Page> extends AbstractPageFile<P>
LinkedHashMap
.cacheSize
). If
the cache is full and another object is added, the LRU (least recently used)
object is dropped.Modifier and Type | Field and Description |
---|---|
protected long |
cacheSize
The maximum number of objects in this cache.
|
protected long |
cacheSizeBytes
Cache size in bytes.
|
protected PageFile<P> |
file
The underlying file of this cache.
|
private static Logging |
logger
Our logger
|
private LinkedHashMap<Integer,P> |
map
The map holding the objects of this cache.
|
readAccess, writeAccess
Constructor and Description |
---|
LRUCache(long cacheSizeBytes,
PageFile<P> file)
Initializes this cache with the specified parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears this cache.
|
void |
close()
Closes this file.
|
void |
deletePage(int pageID)
Deletes the node with the specified id from this file.
|
protected void |
expirePage(P page)
Write page through to disk.
|
void |
flush()
Flushes this caches by writing any entry to the underlying file.
|
PageFileStatistics |
getInnerStatistics()
Get statistics for the inner page file, if present.
|
int |
getNextPageID()
Returns the next page id.
|
int |
getPageSize()
Get the page size of this page file.
|
boolean |
initialize(PageHeader header)
Initialize the page file with the given header - return "true" if the file
already existed.
|
P |
readPage(int pageID)
Retrieves a page from the cache.
|
void |
setCacheSize(int cacheSize)
Sets the maximum size of this cache.
|
void |
setNextPageID(int nextPageID)
Sets the next page id.
|
Integer |
setPageID(P page)
Sets the id of the given page.
|
String |
toString()
Returns a string representation of this cache.
|
void |
writePage(Integer pageID,
P page)
Perform the actual page write operation.
|
getReadOperations, getWriteOperations, resetPageAccess, writePage
private static final Logging logger
protected long cacheSizeBytes
protected long cacheSize
private LinkedHashMap<Integer,P extends Page> map
public P readPage(int pageID)
pageID
- the id of the page to be returnedpublic void writePage(Integer pageID, P page)
AbstractPageFile
writePage
in class AbstractPageFile<P extends Page>
pageID
- Page idpage
- Page to writepublic void deletePage(int pageID)
PageFile
pageID
- the id of the node to be deletedprotected void expirePage(P page)
page
- pagepublic Integer setPageID(P page)
PageFile
page
- the page to set the idpublic int getNextPageID()
PageFile
public void setNextPageID(int nextPageID)
PageFile
nextPageID
- the next page id to be setpublic int getPageSize()
PageFile
public boolean initialize(PageHeader header)
PageFile
header
- Headerpublic void close()
PageFile
public void flush()
public String toString()
public void clear()
public void setCacheSize(int cacheSize)
cacheSize
- the cache size to be setpublic PageFileStatistics getInnerStatistics()
PageFileStatistics