|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.stackmob.sdkapi.caching.CachingService
public abstract class CachingService
CachingService provides fast, distributed, in memory access to data. Since your custom code can run on different machines, you can use CachingService to store the results of operations that take a long time to run (like DataService queries) and then get those results from any other machine. Here's an example showing some common usage of CachingService:
CachingService cachingService = sdkServiceProvider.getCachingService();
String json = null;
try {
json = cachingService.getString("largeQuery", CachingService.utf8Charset());
} finally {}
if(json == null) {
json = executeLargeDatastoreQuery();
//cache the result of the large query for 5 seconds
cachingService.setString("largeQuery", json, CachingService.utf8Charset, 5000);
}
A few things to notice:
get and passing in the key
| Field Summary | |
|---|---|
static Charset |
utf8Charset
|
| Constructor Summary | |
|---|---|
CachingService()
|
|
| Method Summary | |
|---|---|
abstract void |
deleteEventually(String key)
delete the given key in the background. |
abstract byte[] |
getBytes(String key)
get the value for the given key, in raw byte format |
String |
getString(String key)
alias for getString(key, CachingService.utf8Charset()); |
String |
getString(String key,
Charset charset)
get the value for the given key, in String format |
abstract Boolean |
setBytes(String key,
byte[] value,
long ttlMilliseconds)
store the given key/value pair |
Boolean |
setString(String key,
String value,
Charset charset,
long ttlMilliseconds)
store the given key/value pair. |
Boolean |
setString(String key,
String value,
long ttlMilliseconds)
alias for setString(key, value, CachingService.utf8Charset(), ttlMilliseconds) |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Charset utf8Charset
| Constructor Detail |
|---|
public CachingService()
| Method Detail |
|---|
public String getString(String key,
Charset charset)
throws TimeoutException,
RateLimitedException,
DataSizeException
key - the key to getcharset - the charset to use to build the resultant
TimeoutException - if there was a timeout communicating with the cache
RateLimitedException - if there was a rate limit imposed on the cache get request
DataSizeException - if the size of the key or its value in the cache was over the Stackmob-defined limit
public String getString(String key)
throws TimeoutException,
RateLimitedException,
DataSizeException
getString(key, CachingService.utf8Charset());
key - the key to fetch
key
TimeoutException - if there was a timeout communicating with the cache
RateLimitedException - if there was a rate limit imposed on the cache get request
DataSizeException - if the size of the key or its value in the cache was over the Stackmob-defined limit
public abstract byte[] getBytes(String key)
throws TimeoutException,
RateLimitedException,
DataSizeException
key - the key to get
TimeoutException - if there was a timeout communicating with the cache
RateLimitedException - if there was a rate limit imposed on the cache get request
DataSizeException - if the size of the key or its value in the cache was over the Stackmob-defined limit
public Boolean setString(String key,
String value,
Charset charset,
long ttlMilliseconds)
throws TimeoutException,
RateLimitedException,
DataSizeException,
TTLTooBigException
setBytes(key, value.getBytes(charset), ttlMilliseconds)
key - the key to storevalue - the value to store for the given keycharset - the charset to usettlMilliseconds - the TTL for this key/value pair, in milliseconds. if ttlMillseconds <= 0, it's equivalent to passing the longest available TTL
TimeoutException - if there was a timeout communicating with the cache
RateLimitedException - if there was a rate limit imposed1 on this cache get request
TTLTooBigException - if the given TTL was too big for our caching system to handle
DataSizeException
public Boolean setString(String key,
String value,
long ttlMilliseconds)
throws TimeoutException,
RateLimitedException,
DataSizeException,
TTLTooBigException
setString(key, value, CachingService.utf8Charset(), ttlMilliseconds)
key - the key to storevalue - the value to store for the given keyttlMilliseconds - the TTL for this key/value pair, in milliseconds. if ttlMillseconds <= 0, it's equivalent to passing the longest available TTL
TimeoutException - if there was a timeout communicating with the cache
RateLimitedException - if there was a rate limit imposed1 on this cache get request
TTLTooBigException - if the given TTL was too big for our caching system to handle
DataSizeException
public abstract Boolean setBytes(String key,
byte[] value,
long ttlMilliseconds)
throws TimeoutException,
RateLimitedException,
DataSizeException,
TTLTooBigException
key - the key to storevalue - the value to store for keyttlMilliseconds - the TTL for this key/value pair, in milliseconds. if ttlMillseconds <= 0, it's equivalent to passing the longest available TTL
TimeoutException - if there was a timeout communicating with the cache
RateLimitedException - if there was a rate limit imposed1 on this cache get request
TTLTooBigException - if the given TTL was too big for our caching system to handle
DataSizeException
public abstract void deleteEventually(String key)
throws DataSizeException
key - the key to delete
DataSizeException - if the given key is too big
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||