Quadcap Embeddable Database

com.quadcap.sql.file.Cache Class Reference

Inheritance diagram for com.quadcap.sql.file.Cache:

com.quadcap.sql.file.BlockCache List of all members.

Detailed Description

This class manages a number of buffers on an underlying store.

What about write-through policies?

Author:
Stan Bailes

Definition at line 63 of file Cache.java.

Public Member Functions

void init (Object store, int size)
 Initialize the cache.

boolean isReadOnly ()
 Am I read only?

void setReadOnly (boolean v)
 Set the 'read only' flag.

void setLock (Object lock)
 Specify the lock-object to be used to synchronize access to the cache.

Cacheable getCacheable (long key) throws IOException
 Search the cache for the specified key and return the associated cache item if one was found.

Object get (int key) throws IOException
 Get the specified object from the cache, if available; from the underlying store if not.

void put (int key, Object val) throws IOException
 Store the object in the cache.

abstract Cacheable makeCacheable ()
 Factory to create an empty cache slot.

void flush () throws IOException
 Flush all modified items back to the underlying store.

void revert ()
void show (PrintWriter os)

Package Attributes

Object store
Object lock
int size
boolean readOnly
LongMap t
 Map long -> Cacheable.

DList lru = new DList()
 LRU list of free cache items.


Private Member Functions

final Cacheable getCacheable () throws IOException
 Find a free cache slot.


Member Function Documentation

void com.quadcap.sql.file.Cache.flush  )  throws IOException
 

Flush all modified items back to the underlying store.

Definition at line 235 of file Cache.java.

References com.quadcap.sql.file.Cacheable.flush(), com.quadcap.sql.file.Cache.lock, com.quadcap.sql.file.Cache.lru, com.quadcap.util.DListItem.next, and com.quadcap.util.DListItem.obj.

Referenced by com.quadcap.sql.file.BlockFile.flush().

Object com.quadcap.sql.file.Cache.get int  key  )  throws IOException
 

Get the specified object from the cache, if available; from the underlying store if not.

In any case, the object (if found) should be in the cache after this call.

If the object isn't in the cache OR the underlying store, this method should return null, and the contents of both the cache and the underlying store should remain unchanged.

This implementation doesn't change the underlying store, but the cache ends up holding a CacheItem with a null data component.

Parameters:
key the search key
return the data associated with the key

Definition at line 164 of file Cache.java.

References com.quadcap.sql.file.Cacheable.decrRefCount(), com.quadcap.sql.file.Cache.get(), com.quadcap.sql.file.Cache.getCacheable(), com.quadcap.sql.file.Cacheable.getData(), and com.quadcap.sql.file.Cache.lock.

Referenced by com.quadcap.sql.file.Cache.get().

final Cacheable com.quadcap.sql.file.Cache.getCacheable  )  throws IOException [private]
 

Find a free cache slot.

If necessary, seize an existing cache slot, with preference for the "least recently used" item. This function should only be called if the lock on the cache is held by this thread.

Definition at line 205 of file Cache.java.

References com.quadcap.sql.file.Cacheable.flush(), com.quadcap.sql.file.Cacheable.getKey(), com.quadcap.sql.file.Cacheable.getRefCount(), com.quadcap.sql.file.Cacheable.isDirty(), com.quadcap.sql.file.Cache.lru, com.quadcap.sql.file.Cache.makeCacheable(), com.quadcap.util.DListItem.obj, com.quadcap.util.DListItem.prev, com.quadcap.sql.file.Cacheable.setDListItem(), com.quadcap.sql.file.Cache.size, and com.quadcap.sql.file.Cache.t.

Referenced by com.quadcap.sql.file.Cache.get(), com.quadcap.sql.file.Cache.getCacheable(), and com.quadcap.sql.file.Cache.put().

Cacheable com.quadcap.sql.file.Cache.getCacheable long  key  )  throws IOException
 

Search the cache for the specified key and return the associated cache item if one was found.

Otherwise, find a free cache item and initialize it from the underlying store.

Parameters:
key the search key
Returns:
the cache item associated with the specified key.

Definition at line 122 of file Cache.java.

References com.quadcap.sql.file.Cache.getCacheable(), com.quadcap.sql.file.Cacheable.getDListItem(), com.quadcap.sql.file.Cacheable.incrRefCount(), com.quadcap.sql.file.Cacheable.init(), com.quadcap.sql.file.Cache.lock, com.quadcap.sql.file.Cache.lru, com.quadcap.sql.file.Cache.readOnly, com.quadcap.sql.file.Cacheable.setReadOnly(), com.quadcap.sql.file.Cache.size, com.quadcap.sql.file.Cache.store, and com.quadcap.sql.file.Cache.t.

Referenced by com.quadcap.sql.file.BlockFile.getPage().

void com.quadcap.sql.file.Cache.init Object  store,
int  size
 

Initialize the cache.

Parameters:
s the underlying store
size the size of the cache

Definition at line 85 of file Cache.java.

References com.quadcap.sql.file.Cache.init(), com.quadcap.sql.file.Cache.lru, and com.quadcap.sql.file.Cache.t.

Referenced by com.quadcap.sql.file.BlockFile.BlockFile(), and com.quadcap.sql.file.Cache.init().

boolean com.quadcap.sql.file.Cache.isReadOnly  ) 
 

Am I read only?

Definition at line 96 of file Cache.java.

References com.quadcap.sql.file.Cache.readOnly.

abstract Cacheable com.quadcap.sql.file.Cache.makeCacheable  )  [pure virtual]
 

Factory to create an empty cache slot.

Only a fixed number of cache slots should be created, and they should then be recycled, never destroyed.

Implemented in com.quadcap.sql.file.BlockCache.

Referenced by com.quadcap.sql.file.Cache.getCacheable().

void com.quadcap.sql.file.Cache.put int  key,
Object  val
throws IOException
 

Store the object in the cache.

The object will be marked dirty, and will eventually be written back to the underlying store.

Definition at line 181 of file Cache.java.

References com.quadcap.sql.file.Cacheable.decrRefCount(), com.quadcap.sql.file.Cache.getCacheable(), com.quadcap.sql.file.Cache.lock, com.quadcap.sql.file.Cache.put(), and com.quadcap.sql.file.Cacheable.setData().

Referenced by com.quadcap.sql.file.Cache.put().

void com.quadcap.sql.file.Cache.revert  ) 
 

Definition at line 249 of file Cache.java.

References com.quadcap.sql.file.Cache.lock, com.quadcap.sql.file.Cache.lru, com.quadcap.sql.file.Cache.size, and com.quadcap.sql.file.Cache.store.

Referenced by com.quadcap.sql.file.BlockFile.revert().

void com.quadcap.sql.file.Cache.setLock Object  lock  ) 
 

Specify the lock-object to be used to synchronize access to the cache.

If the lock isn't specified, it defaults to the cache object itself.

Parameters:
lock the lock object

Definition at line 110 of file Cache.java.

References com.quadcap.sql.file.Cache.setLock().

Referenced by com.quadcap.sql.file.BlockFile.BlockFile(), and com.quadcap.sql.file.Cache.setLock().

void com.quadcap.sql.file.Cache.setReadOnly boolean  v  ) 
 

Set the 'read only' flag.

Definition at line 101 of file Cache.java.

References com.quadcap.sql.file.Cache.setReadOnly().

Referenced by com.quadcap.sql.file.BlockFile.BlockFile(), and com.quadcap.sql.file.Cache.setReadOnly().

void com.quadcap.sql.file.Cache.show PrintWriter  os  ) 
 

Definition at line 256 of file Cache.java.

References com.quadcap.sql.file.Cache.lock, com.quadcap.sql.file.Cache.lru, and com.quadcap.sql.file.Cache.show().

Referenced by com.quadcap.sql.file.Cache.show(), and com.quadcap.sql.file.BlockFile.showCache().


Member Data Documentation

Object com.quadcap.sql.file.Cache.lock [package]
 

Definition at line 65 of file Cache.java.

Referenced by com.quadcap.sql.file.Cache.flush(), com.quadcap.sql.file.Cache.get(), com.quadcap.sql.file.Cache.getCacheable(), com.quadcap.sql.file.Cache.put(), com.quadcap.sql.file.Cache.revert(), and com.quadcap.sql.file.Cache.show().

DList com.quadcap.sql.file.Cache.lru = new DList() [package]
 

LRU list of free cache items.

Definition at line 77 of file Cache.java.

Referenced by com.quadcap.sql.file.Cache.flush(), com.quadcap.sql.file.Cache.getCacheable(), com.quadcap.sql.file.Cache.init(), com.quadcap.sql.file.Cache.revert(), and com.quadcap.sql.file.Cache.show().

boolean com.quadcap.sql.file.Cache.readOnly [package]
 

Definition at line 67 of file Cache.java.

Referenced by com.quadcap.sql.file.Cache.getCacheable(), and com.quadcap.sql.file.Cache.isReadOnly().

int com.quadcap.sql.file.Cache.size [package]
 

Definition at line 66 of file Cache.java.

Referenced by com.quadcap.sql.file.Cache.getCacheable(), and com.quadcap.sql.file.Cache.revert().

Object com.quadcap.sql.file.Cache.store [package]
 

Definition at line 64 of file Cache.java.

Referenced by com.quadcap.sql.file.Cache.getCacheable(), and com.quadcap.sql.file.Cache.revert().

LongMap com.quadcap.sql.file.Cache.t [package]
 

Map long -> Cacheable.

Definition at line 72 of file Cache.java.

Referenced by com.quadcap.sql.file.Cache.getCacheable(), and com.quadcap.sql.file.Cache.init().