Tobias
Tobias

Reputation: 7415

does caching values of SharedPreferences make sense?

In my current Android app I have several settings stored in SharedPreferences and one object which handles access to them. I now wonder if it makes sense to cache the values or if doesn't mater much accessing them like:

public final boolean isxxxEnabled() {
    return preferences.getBoolean("xxx", false);
}

instead of

public final boolean isxxxEnabled() {
            // check if value changed
            // if not, check if value is cached
            // decide whether to return cached or new
            // cache value
    return 
}

Upvotes: 14

Views: 3366

Answers (1)

Kurtis Nusbaum
Kurtis Nusbaum

Reputation: 30825

Caching shared preferences isn't really necessary. The speed up you're gonna get will be marginal at best and it's going to increase the code you have to write. I'd say don't bother.

Upvotes: 8

Related Questions