-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a6c8b1
commit e39ee8c
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.catter2.cat_api; | ||
|
||
import android.util.Log; | ||
|
||
public class CacheTheCatAPI implements TheCatAPI { | ||
private static String TAG = "CacheTheCatAPI"; | ||
|
||
private TheCatAPI service; | ||
private CatImagesModel lastResponse; | ||
|
||
public CacheTheCatAPI(TheCatAPI service) { | ||
this.service = service; | ||
} | ||
|
||
@Override | ||
public void getCatsWithHats(final Callback callback) { | ||
if (lastResponse != null) { | ||
Log.d(TAG, "Using cached response."); | ||
callback.response(lastResponse); | ||
} else { | ||
Log.d(TAG, "Querying a new response."); | ||
service.getCatsWithHats(new Callback() { | ||
@Override | ||
public void response(CatImagesModel response) { | ||
Log.d(TAG, "Saving response to cache."); | ||
lastResponse = response; | ||
callback.response(response); | ||
} | ||
}); | ||
} | ||
} | ||
} |