|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.github.ignition.support.cache.CachedModel
public abstract class CachedModel
Superclass of all objects to be stored in ModelCache
.
To save an object to the cache use save(ModelCache)
, when updating an object with any
new data use reload(ModelCache)
, and when wanting to find an object from the cache, use
find(ModelCache, String, Class)
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface android.os.Parcelable |
---|
android.os.Parcelable.Creator<T> |
Field Summary |
---|
Fields inherited from interface android.os.Parcelable |
---|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE |
Constructor Summary | |
---|---|
CachedModel()
Simple parameter-less constructor. |
|
CachedModel(android.os.Parcel source)
Constructor setting variables from parcel. |
|
CachedModel(String id)
Constructor setting ID given. |
Method Summary | |
---|---|
abstract String |
createKey(String id)
Method called to determine a key in the cache using the object's id e.g.: |
int |
describeContents()
|
static CachedModel |
find(ModelCache modelCache,
String id,
Class<? extends CachedModel> clazz)
Method for looking up object in cache. |
String |
getId()
Returns ID of object used in key generation. |
String |
getKey()
|
void |
readFromParcel(android.os.Parcel source)
Saves data to parcel. |
boolean |
reload(ModelCache modelCache)
Attempts to reload any new data from cache. |
abstract boolean |
reloadFromCachedModel(ModelCache modelCache,
CachedModel cachedModel)
Method called to reload any data from a more recently stored object e.g.: |
boolean |
save(ModelCache modelCache)
Attempts to store the object in the cache using this object's key. |
protected boolean |
save(ModelCache modelCache,
String saveKey)
Attempts to save the object in the cache using a given key. |
void |
setId(String id)
Set ID of object used in key generation. |
void |
writeToParcel(android.os.Parcel dest,
int flags)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CachedModel()
public CachedModel(android.os.Parcel source) throws IOException
source
- Parcel to be read from.
IOException
public CachedModel(String id)
id
- ID of new object (used when generating cache key).Method Detail |
---|
public String getId()
public void setId(String id)
id
- ID of new object (used when generating cache key).public String getKey()
public static CachedModel find(ModelCache modelCache, String id, Class<? extends CachedModel> clazz)
modelCache
- Cache to be searched.id
- ID of object to be searched for.clazz
- Class of desired cached object
public boolean save(ModelCache modelCache)
public boolean save(ModelCache modelCache) {
return super.save(modelCache) && super.save(modelCache, super.getKey());
}
modelCache
- Cache to save to.
protected boolean save(ModelCache modelCache, String saveKey)
modelCache
- Cache to save to.saveKey
- Key to be saved under.
public boolean reload(ModelCache modelCache)
modelCache
- Cache to be reloaded from.
public abstract String createKey(String id)
public String createKey(String id) {
"example_object_" + id;
}
id
- ID of object to be stored.
public abstract boolean reloadFromCachedModel(ModelCache modelCache, CachedModel cachedModel)
public boolean reloadFromCachedModel(ModelCache modelCache, CachedModel cachedModel) {
ExampleObject cachedExampleObject = (ExampleObject) cachedModel;
this.exampleVariable = cachedExampleObject.exampleVariable;
return false;
}
Can also be used to reload internal cached objects. e.g.:
public boolean reloadFromCachedModel(ModelCache modelCache, CachedModel cachedModel) {
ExampleObject cachedExampleObject = (ExampleObject) cachedModel;
this.exampleInternalCachedObject = cachedExampleObject.exampleInternalCachedObject;
return this.exampleInternalCachedObject.reload(modelCache);
}
modelCache
- Cache that is currently being reloaded from.cachedModel
- Latest version of object in cache.
public int describeContents()
describeContents
in interface android.os.Parcelable
Parcelable.describeContents()
public void writeToParcel(android.os.Parcel dest, int flags)
writeToParcel
in interface android.os.Parcelable
Parcelable.writeToParcel(android.os.Parcel, int)
public void readFromParcel(android.os.Parcel source) throws IOException
source
- Parcel to save to.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |