
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 int |
cacheSize
The maximum number of objects in this cache.
|
protected int |
cacheSizeBytes
Cache size in bytes.
|
protected PageFile<P> |
file
The underlying file of this cache.
|
private static Logging |
LOG
Our class logger.
|
private LinkedHashMap<Integer,P> |
map
The map holding the objects of this cache.
|
| Constructor and Description |
|---|
LRUCache(int 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.
|
protected Logging |
getLogger()
Get the class logger.
|
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.
|
void |
logStatistics()
Log some statistics to the appropriate logger.
|
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.
|
int |
setPageID(P page)
Sets the id of the given page.
|
String |
toString()
Returns a string representation of this cache.
|
void |
writePage(int pageID,
P page)
Perform the actual page write operation.
|
countRead, countWrite, writePageprivate static final Logging LOG
protected int cacheSizeBytes
protected int cacheSize
private LinkedHashMap<Integer,P extends Page> map
public P readPage(int pageID)
pageID - the id of the page to be returnedpublic void writePage(int pageID,
P page)
AbstractPageFilewritePage in class AbstractPageFile<P extends Page>pageID - Page idpage - Page to writepublic void deletePage(int pageID)
PageFilepageID - the id of the node to be deletedprotected void expirePage(P page)
page - pagepublic int setPageID(P page)
PageFilepage - the page to set the idpublic int getNextPageID()
PageFilepublic void setNextPageID(int nextPageID)
PageFilenextPageID - the next page id to be setpublic int getPageSize()
PageFilepublic boolean initialize(PageHeader header)
PageFileheader - Headerpublic void close()
PageFilepublic void flush()
public String toString()
public void clear()
public void setCacheSize(int cacheSize)
cacheSize - the cache size to be setpublic void logStatistics()
PageFilelogStatistics in interface PageFile<P extends Page>logStatistics in class AbstractPageFile<P extends Page>protected Logging getLogger()
AbstractPageFilegetLogger in class AbstractPageFile<P extends Page>