java.lang.Object | |
↳ | com.salesforce.android.knowledge.core.offline.OfflineResourceCache |
This class can be used to cache online resources for later offline viewing.
You can retrieve an instance of this class from getCache()
.
Resources will be
written into the cache automatically if a non-disabled OfflineResourceConfig
object is
passed to offlineResourceConfig(OfflineResourceConfig)
at configuration time. It is not usually necessary to call putResource(String, Source)
manually, but you may wish to use getResource(String)
to retrieved a cached resource
when rendering article content offline.
The cache is backed by a disk-based LRU cache which has a maximum size as specified in
maxSize(int)
.
Older article resources are evicted to make room as necessary.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
class | OfflineResourceCache.Builder | Builder class for OfflineResourceCache . |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | CACHE_KEY_HASH_SEED | ||||||||||
String | CACHE_SUB_DIRECTORY |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
protected static final ServiceLogger | log |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
OfflineResourceCache(OfflineResourceCache.Builder builder) |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Async<Void> |
clear()
Empty the cache.
| ||||||||||
static void |
clearCache(Context context, AuthenticatedUser authenticatedUser)
Clear the cache for the specified user.
| ||||||||||
boolean |
delete()
Delete the cache from disk by removing all associated files.
| ||||||||||
static void |
deleteCache(Context context, AuthenticatedUser authenticatedUser)
Delete the cache for the specified user from disk.
| ||||||||||
static void |
deleteCache(Context context)
Delete offline resource cache for all users.
| ||||||||||
InputStream |
getResource(String url)
Fetches a cached resource from the filesystem, if present.
| ||||||||||
boolean |
putResource(String url, Source source)
Puts the supplied resource into the cache.
| ||||||||||
long |
size()
Return the current approximate size of the cache on disk.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Empty the cache. This deletes any resources stored on disk.
Clear the cache for the specified user. Clearing is performed on a background thread.
context | A Context , required for accessing the cache directory |
---|---|
authenticatedUser | The the user whose cache will be cleared |
Delete the cache from disk by removing all associated files.
Delete the cache for the specified user from disk.
context | A Context , required for accessing the cache directory |
---|---|
authenticatedUser | The the user whose cache will be deleted |
Delete offline resource cache for all users.
context | A Context , required for accessing the cache directory
|
---|
Fetches a cached resource from the filesystem, if present. Note that this method is synchronous and should not be accessed from the main thread.
url | The online URL of the resource. |
---|
Puts the supplied resource into the cache. Note that this is synchronous and should not be accessed from the main thread.
url | The url from which the resource was downloaded. |
---|---|
source | The source bytes for the resource. |
Return the current approximate size of the cache on disk.