public synchronized void cache(@NonNull List<Event> toCache) { if (!isCachingEnabled() || toCache.isEmpty()) return; checkCacheLimits(); long startTime = System.currentTimeMillis(); File container = writeEventFile(toCache); if (container != null) { mEventContainer.add(container); mCurrentSize += container.length(); } long stopTime = System.currentTimeMillis(); Timber.tag(TAG).d("Caching of %d events took %dms (%s)", toCache.size(), (stopTime - startTime), container); }
public synchronized void cache(@NonNull List<Event> toCache) { if (!isCachingEnabled() || toCache.isEmpty()) return; checkCacheLimits(); long startTime = System.currentTimeMillis(); File container = writeEventFile(toCache); if (container != null) { mEventContainer.add(container); mCurrentSize += container.length(); } long stopTime = System.currentTimeMillis(); Timber.tag(TAG).d("Caching of %d events took %dms (%s)", toCache.size(), (stopTime - startTime), container); }
@NonNull public synchronized List<Event> uncache() { List<Event> events = new ArrayList<>(); if (!isCachingEnabled()) return events; checkCacheLimits(); long startTime = System.currentTimeMillis(); while (!mEventContainer.isEmpty()) { File head = mEventContainer.poll(); if (head != null) { events.addAll(readEventFile(head)); if (!head.delete()) Timber.tag(TAG).e("Failed to delete cache container %s", head.getPath()); } } long stopTime = System.currentTimeMillis(); Timber.tag(TAG).d("Uncaching of %d events took %dms", events.size(), (stopTime - startTime)); return events; }
@NonNull public synchronized List<Event> uncache() { List<Event> events = new ArrayList<>(); if (!isCachingEnabled()) return events; checkCacheLimits(); long startTime = System.currentTimeMillis(); while (!mEventContainer.isEmpty()) { File head = mEventContainer.poll(); if (head != null) { events.addAll(readEventFile(head)); if (!head.delete()) Timber.tag(TAG).e("Failed to delete cache container %s", head.getPath()); } } long stopTime = System.currentTimeMillis(); Timber.tag(TAG).d("Uncaching of %d events took %dms", events.size(), (stopTime - startTime)); return events; }