org.dllearner.kb.sparql
Class Cache

java.lang.Object
  extended by org.dllearner.kb.sparql.Cache
All Implemented Interfaces:
Serializable

public class Cache
extends Object
implements Serializable

SPARQL query cache to avoid possibly expensive multiple queries. The queries and their results are written to files. A cache has an associated cache directory where all files are written. Each SPARQL query and its result is written to one file. The name of this file is a hash of the query. The result of the query is written as JSON serialisation of the SPARQL XML result, see http://www.w3.org/TR/rdf-sparql-json-res/. Apart from the query and its result, a timestamp of the query is stored. After a configurable amount of time, query results are considered outdated. If a cached result of a SPARQL query exists, but is too old, the cache behaves as if the cached result would not exist. TODO: We are doing md5 hashing at the moment, so in rare cases different SPARQL queries can be mapped to the same file. Support for such scenarios needs to be included.

Author:
Sebastian Hellmann, Sebastian Knappe, Jens Lehmann
See Also:
Serialized Form

Constructor Summary
Cache(String cacheDir)
          Constructor for the cache itself.
 
Method Summary
 void clearCache()
          deletes all Files in the cacheDir, does not delete the cacheDir itself, and can thus still be used without creating a new Cache Object
 String executeSparqlQuery(SparqlQuery query)
          Takes a SPARQL query (which has not been evaluated yet) as argument and returns a JSON result set.
static Cache getDefaultCache()
           
static String getDefaultCacheDir()
          the default cachedir normally is "cache".
static String getPersistantCacheDir()
          a more persistant cache used for example generation."
static Cache getPersistentCache()
          A Persistant cache is stored in the folder cachePersistant.
 void setFreshnessInDays(int days)
          Changes how long cached results will stay fresh (default 15 days).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cache

public Cache(String cacheDir)
Constructor for the cache itself.

Parameters:
cacheDir - Where the base path to the cache is .
Method Detail

getPersistentCache

public static Cache getPersistentCache()
A Persistant cache is stored in the folder cachePersistant. It has longer freshness 365 days and is mainly usefull for developing

Returns:
a Cache onject

getDefaultCache

public static Cache getDefaultCache()
Returns:
the default cache object

getDefaultCacheDir

public static String getDefaultCacheDir()
the default cachedir normally is "cache".

Returns:
Default Cache Dir

getPersistantCacheDir

public static String getPersistantCacheDir()
a more persistant cache used for example generation."cachePersistant"

Returns:
persistant Cache Dir

executeSparqlQuery

public String executeSparqlQuery(SparqlQuery query)
Takes a SPARQL query (which has not been evaluated yet) as argument and returns a JSON result set. The result set is taken from this cache if the query is stored here. Otherwise the query is send and its result added to the cache and returned. Convenience method.

Parameters:
query - The SPARQL query.
Returns:
Jena result set in JSON format

clearCache

public void clearCache()
deletes all Files in the cacheDir, does not delete the cacheDir itself, and can thus still be used without creating a new Cache Object


setFreshnessInDays

public void setFreshnessInDays(int days)
Changes how long cached results will stay fresh (default 15 days).

Parameters:
days - number of days


SourceForge.net Logo DL-Learner is licenced under the terms of the GNU General Public License.
Copyright © 2007-2008 Jens Lehmann