OverviewSingleDeprecated

jsx3.app

class Cache

Object
->jsx3.lang.Object
  ->jsx3.app.Cache

All Implemented Interfaces:

jsx3.util.EventDispatcher

class Cache
extends jsx3.lang.Object
Provides cached access to XML and XSL data.

Events

Cache instances publish two types of events for every operation that modifies the contents of the cache. The schemas of the two event types are and

Asynchronous Loading

Cache documents can be loaded asychronously with the getOrOpenAsync() method. This method returns the corresponding document synchronously if it already exists in the cache. If the document does not exist in the cache, then it is loaded asynchronously and the method returns a placeholder document. The namespace URI of this placeholder document is Cache.XSDNS and its root node name is "loading".

Since the cache stores this placeholder document until the document finishes loading, subsequent calls to synchronous APIs (getDocument(), getOrOpenDocument(), etc) may also return the placeholder document. It is therefore important to check the namespace of the returned document when any code uses the asynchronous APIs.

Once a document finishes loading asynchronously the placeholder document is replaced with the loaded document. This change in value causes the cache to publish a pair of events of action Cache.CHANGE. If loading the document fails or times out the placeholder document is instead replaced with another placeholder document. This document also has a URI namespace of Cache.XSDNS. Its root node name may be either "error" or "timeout". If the root node name is "error" then the root node has an attribute, also named "error", which contains the XML error message.

Field Summary
static String
ADD
Event action.
static int
ASYNC_TIMEOUT
The number of milliseconds before asynchronous document loads time out.
static String
CHANGE
Event subject and action.
static String
REMOVE
Event action.
static String
XSDNS
Constructor Summary
void
Creates a new instance of this class.
Method Summary
jsx3.xml.Document
clearById(strId : String)
Removes the document stored in this cache under id strId.
Array<String>
clearByTimestamp(intTimestamp : int | Date)
Removes all documents placed in this cache before intTimestamp.
void
Removes all references to documents contained in this cache.
jsx3.xml.Document
getDocument(strId : String)
Returns the document stored in this cache under id strId.
jsx3.xml.Document
getOrOpenAsync(strURL : String | jsx3.net.URI, strId : String, objClass : jsx3.lang.Class)
Asynchronously loads an xml document and stores it in this cache.
jsx3.xml.Document
getOrOpenDocument(strURL : String | jsx3.net.URI, strId : String, objClass : jsx3.lang.Class)
Retrieves a document from this cache or, if this cache contains no such document, loads the document synchronously and returns it.
int
getTimestamp(strId : String)
Returns the timestamp from when the document stored under id strId was stored in this cache.
boolean
isSystem(strId : String)
Deprecated.
Array<String>
Returns a list of all the keys in this cache instance.
jsx3.xml.Document
openDocument(strURL : String | jsx3.net.URI, strId : String, objClass : jsx3.lang.Class)
Synchronously loads an xml document, stores it in this cache, and returns the loaded document.
void
setDocument(strId : String, objDocument : jsx3.xml.Document)
Stores the document objDocument in this cache under id strId.
Methods Inherited From jsx3.util.EventDispatcher
publish, subscribe, unsubscribe, unsubscribeAll
Methods Inherited From jsx3.lang.Object
clone, equals, eval, getClass, getInstanceOf, getInstanceOfClass, getInstanceOfPackage, instanceOf, isInstanceOf, isSubclassOf, jsxmix, jsxsuper, jsxsupermix, setInstanceOf, toString
Field Detail

ADD

static final String ADD
Event action.

ASYNC_TIMEOUT

static int ASYNC_TIMEOUT
The number of milliseconds before asynchronous document loads time out.

CHANGE

static final String CHANGE
Event subject and action.

REMOVE

static final String REMOVE
Event action.

XSDNS

static String XSDNS
Constructor Detail

init

void init()
Creates a new instance of this class.
Method Detail

clearById

jsx3.xml.Document clearById(strId : String)
Removes the document stored in this cache under id strId.

Parameters:

strId

Returns:

the remove document, if any.  

clearByTimestamp

Array<String> clearByTimestamp(intTimestamp : int | Date)
Removes all documents placed in this cache before intTimestamp.

Parameters:

intTimestampepoch seconds or a date object.

Returns:

the ids of the removed documents.  

destroy

void destroy()
Removes all references to documents contained in this cache. This cache is no longer usable after calling this method.

getDocument

jsx3.xml.Document getDocument(strId : String)
Returns the document stored in this cache under id strId.

Parameters:

strId

Returns:

the stored document or null if none exists.  

getOrOpenAsync

jsx3.xml.Document getOrOpenAsync(strURL : String | jsx3.net.URI, strId : String, objClass : jsx3.lang.Class)
Asynchronously loads an xml document and stores it in this cache.

Parameters:

strURLurl (relative or absolute) the URI of the document to open.
strIdthe id under which to store the document. If this parameter is not provided, the strURL parameter is used as the id.
objClassjsx3.xml.Document (default value) or one of its subclasses. The class with which to instantiate the new document instance.

Returns:

the document retrieved from the cache or a placeholder document if the document is in the process of loading asynchronously. 

Since:

3.5

getOrOpenDocument

jsx3.xml.Document getOrOpenDocument(strURL : String | jsx3.net.URI, strId : String, objClass : jsx3.lang.Class)
Retrieves a document from this cache or, if this cache contains no such document, loads the document synchronously and returns it.

Parameters:

strURLthe URI of the document.
strIdthe id under which the document is/will be stored. If this parameter is not provided, the strURL parameter is used as the id.
objClassjsx3.xml.Document (default value) or one of its subclasses. The class with which to instantiate the new document instance if a new document is opened.

Returns:

the document retrieved from the cache or loaded.  

getTimestamp

int getTimestamp(strId : String)
Returns the timestamp from when the document stored under id strId was stored in this cache.

Parameters:

strIdthe id under which the document is stored.

Returns:

the timestamp as an integer (epoch seconds) or null if no such document exists in this cache.  

isSystem

boolean isSystem(strId : String)
Deprecated.
returns whether or not the given document in the cache is owned by the system. If no document by the given ID exists, false is returned.

Parameters:

strIdunique identifier for the jsx3.xml.DocumentInstance instance when it was placed in the cache

Returns:

false

keys

Array<String> keys()
Returns a list of all the keys in this cache instance.

Returns:

 

openDocument

jsx3.xml.Document openDocument(strURL : String | jsx3.net.URI, strId : String, objClass : jsx3.lang.Class)
Synchronously loads an xml document, stores it in this cache, and returns the loaded document.

Parameters:

strURLurl (relative or absolute) the URI of the document to open.
strIdthe id under which to store the document. If this parameter is not provided, the strURL parameter is used as the id.
objClassjsx3.xml.Document (default value) or one of its subclasses. The class with which to instantiate the new document instance.

Returns:

the loaded document object.  

setDocument

void setDocument(strId : String, objDocument : jsx3.xml.Document)
Stores the document objDocument in this cache under id strId. If a document already exists in this cache under strId then that document is removed from the cache.

Parameters:

strIdthe id under which to store objDocument.
objDocument