Question

I need to create an application,that should contain two storage,one is persistent storage and another one is cache storage.After loading, the application should check the username and password with the cache storage data if it is empty then it should check with the persistent storage.How to accomplish this task?Is there any separate concept of cache or we have create the persistent as cache.please help me.

Was it helpful?

Solution

You can use RecordStore which is also persistent, or RuntimeStore which is shared between all apps but is non persistent.

Alternatively you can use some custom storage class to implement cache functionality, storing, updating values in that class, sharing it as a field of Application class:

class Cache {

    String mName = null;
    String mPhone = null;
}

public class CacheApp extends UiApplication {
    Cache mCache = null;
    public static void main(String[] args) {
        CacheApp app = new CacheApp();
        app.enterEventDispatcher();
    }

    public CacheApp() {
        initCache();

        CacheScr scr = new CacheScr();
        pushScreen(scr);
    }

    private void initCache() {
        mCache = new Cache();
        mCache.mName = "Name";
        mCache.mPhone = "Phone";
    }
}

class CacheScr extends MainScreen {

    public CacheScr() {
        CacheApp app = (CacheApp) UiApplication.getUiApplication();
        String name = app.mCache.mName;
        String phone = app.mCache.mPhone;
    }
}

OTHER TIPS

Coldice is correct, however I fail to see why one would use a store separate from PersistentStore (or RecordStore) for data that must endure and may be shared, and RuntimeStore for data which is shared but not durable. This just seems to be adding complexity to normal application transient storage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top