Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
iagocanalejas committed Jan 18, 2017
2 parents a3a4f0b + 13a2c9d commit 06a25a0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 1.1
- Added `remove` method for invalidate a cached call.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ dependencies {
retrofitBuilder.addCallAdapterFactory(new CachedCallFactory(mCache));
```
4. Use it as normal retrofit. Just remember to use `CachedCall`. All retrofit methods are included, and you can also call `refresh(callback)` to avoid looking in the cache.
4. Use it as normal retrofit. Just remember to use `CachedCall`. All retrofit methods are included, and you can also call `refresh(callback)` to avoid looking in the cache or `remove()` to invalidate a cached call.
```java
CachedCall<MyObject> call = ...
call.refresh(new Callback<MyObject>() {
...
});
call.remove();
```
# Pull Requests
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

ext {
// Base
libraryCode = 1
libraryName = '1.0.0'
libraryCode = 2
libraryName = '1.1'
compileSdkVersion = 25
buildToolsVersion = '25.0.2'
supportLib = '25.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.andiag.retrocache.cache.RetroCache;
import com.andiag.retrocache.interfaces.CachedCall;
Expand All @@ -23,7 +24,7 @@ public class CachedCallFactory extends CallAdapter.Factory {
private final Cache<String, byte[]> mCachingSystem;
private final Executor mAsyncExecutor;

public CachedCallFactory(Context context, int appVersion) {
public CachedCallFactory(@NonNull Context context, int appVersion) {
this.mCachingSystem = RetroCache.getDualCache(context, appVersion);
this.mAsyncExecutor = new Executor() {
@Override
Expand All @@ -33,7 +34,7 @@ public void execute(@NonNull Runnable command) {
};
}

public CachedCallFactory(Cache<String, byte[]> cachingSystem) {
public CachedCallFactory(@NonNull Cache<String, byte[]> cachingSystem) {
this.mCachingSystem = cachingSystem;
this.mAsyncExecutor = new Executor() {
@Override
Expand All @@ -43,7 +44,8 @@ public void execute(@NonNull Runnable command) {
};
}

public CachedCallFactory(Cache<String, byte[]> cachingSystem, Executor executor) {
public CachedCallFactory(@NonNull Cache<String, byte[]> cachingSystem,
@Nullable Executor executor) {
this.mCachingSystem = cachingSystem;
this.mAsyncExecutor = executor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public Response<T> execute() throws IOException {
return mCall.execute();
}

@Override
public void remove() {
mCachingSystem.remove(ResponseUtils.urlToKey(mCall.request().url()));
}

@Override
public void cancel() {
mCall.cancel();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.andiag.retrocache.cache;

import android.content.Context;
import android.support.annotation.NonNull;

import com.andiag.retrocache.utils.ByteArraySerializer;
import com.andiag.retrocache.utils.EntryCountSizeOf;
Expand Down Expand Up @@ -38,14 +39,16 @@ public static DualCache<String, byte[]> getRamCache(int appVersion) {
* @param appVersion used to invalidate the cache.
* @return {@link DualCache}.
*/
public static DualCache<String, byte[]> getDualCache(Context context, int appVersion) {
public static DualCache<String, byte[]> getDualCache(@NonNull Context context, int appVersion) {
return new Builder<String, byte[]>(CACHE_NAME, appVersion)
.useReferenceInRam(REASONABLE_MEM_ENTRIES, new EntryCountSizeOf())
.useSerializerInDisk(REASONABLE_DISK_SIZE, true, new ByteArraySerializer(), context)
.build();
}

public static DualCache<String, byte[]> getVolatileCache(Context context, int appVersion) {
public static DualCache<String, byte[]> getVolatileCache(@NonNull Context context,
int appVersion) {

return new Builder<String, byte[]>(CACHE_NAME, appVersion)
.useReferenceInRam(REASONABLE_MEM_ENTRIES, new EntryCountSizeOf())
.useSerializerInDisk(REASONABLE_DISK_SIZE, true, new ByteArraySerializer(), context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public interface CachedCall<T> extends Call<T>, Cloneable {
*/
Type responseType();

/**
* Remove a cached call if exists
*/
void remove();

}

0 comments on commit 06a25a0

Please sign in to comment.