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, writePage
private 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)
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 int 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 void logStatistics()
PageFile
logStatistics
in interface PageFile<P extends Page>
logStatistics
in class AbstractPageFile<P extends Page>
protected Logging getLogger()
AbstractPageFile
getLogger
in class AbstractPageFile<P extends Page>
Copyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.