예제 #1
0
    public ModelCache build() {
      final ModelCache cache = new ModelCache();

      if (isValidOptionsForMemoryCache()) {
        cache.setMemoryCache(new LruCache<String, CacheItem>(mMemoryCacheMaxSize));
      }

      if (isValidOptionsForDiskCache()) {
        new AsyncTask<Void, Void, DiskLruCache>() {

          @Override
          protected DiskLruCache doInBackground(Void... params) {
            try {
              DiskLruCache c = DiskLruCache.open(mDiskCacheLocation, 0, 2, mDiskCacheMaxSize);
              cache.setDiskCache(c);
              return c;
            } catch (IOException e) {
              e.printStackTrace();
              return null;
            }
          }

          @Override
          protected void onPostExecute(DiskLruCache result) {
            // cache.setDiskCache(result);
          }
        }.execute();
      }

      return cache;
    }
예제 #2
0
 @Override
 protected Object doInBackground(Void... voids) {
   if (modelCache != null) {
     return modelCache.put(key, obj, expiresAt);
   } else {
     return null;
   }
 }
예제 #3
0
 @Override
 protected Object doInBackground(Void... voids) {
   if (modelCache != null) {
     return modelCache.get(key, checkExpiration);
   } else {
     return null;
   }
 }