All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.segment.analytics.TraitsCache Maven / Gradle / Ivy

There is a newer version: 2.5.3
Show newest version
package com.segment.analytics;

import android.content.Context;

import static com.segment.analytics.Utils.getSharedPreferences;
import static com.segment.analytics.Utils.isNullOrEmpty;

class TraitsCache {
  private static final String TRAITS_CACHE_PREFIX = "traits-";

  private final StringCache stringCache;
  private Traits traits;

  TraitsCache(Context context, String tag) {
    stringCache = new StringCache(getSharedPreferences(context), TRAITS_CACHE_PREFIX + tag);
    if (isNullOrEmpty(stringCache.get())) {
      traits = new Traits(context);
    } else {
      traits = new Traits(stringCache.get());
    }
  }

  Traits get() {
    return traits;
  }

  void save() {
    stringCache.set(traits.toString());
  }

  void delete(Context context) {
    stringCache.delete();
    traits = new Traits(context);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy