public class

SQLiteFileCache

extends Object
implements FileCache
java.lang.Object
   ↳ com.kinvey.android.offline.SQLiteFileCache

Class Overview

File Caching allows your application to store files locally in an arbitrary location, and maintains metadata about the contents of the cache in sqlite table.

When saving a new file into the directory, an AsyncTask will be kicked off which will delete the oldest files until the cache size is under the threshold.

Summary

Constants
String TAG
Public Constructors
SQLiteFileCache(Context context)
Load up a file cache using internal storage's cache directory
SQLiteFileCache(File location)
Load up a file cache using a custom defined location
Public Methods
FileInputStream get(AbstractClient client, String id)
Get a file from the local file cache.
File getCacheDir()
get a pointer to the current cache dir
String getFilenameForID(AbstractClient client, String id)
Retrieve the filename of the file associated with the provided id
synchronized void save(AbstractClient client, FileMetaData meta, byte[] data)
Save a file into the file cache
void trimCache(Context context)
This method compares the current size of all files in the cache dir to the limit size.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.kinvey.java.offline.FileCache

Constants

public static final String TAG

Constant Value: "kinvey - filecache"

Public Constructors

public SQLiteFileCache (Context context)

Load up a file cache using internal storage's cache directory

public SQLiteFileCache (File location)

Load up a file cache using a custom defined location

Public Methods

public FileInputStream get (AbstractClient client, String id)

Get a file from the local file cache. If the file is not present, then this method will return null.

the file cache uses a sqlite table internally to maintain metadata about all locally stored files.

Parameters
client the current active client associated with the applications
id the id of the file to attempt to load
Returns
  • a `FileInputStream` for the file associated with the provided id, or null

public File getCacheDir ()

get a pointer to the current cache dir

Returns
  • the cache directory

public String getFilenameForID (AbstractClient client, String id)

Retrieve the filename of the file associated with the provided id

Parameters
client the applications' client
id the id of the file to lookup
Returns
  • null or the filename

public synchronized void save (AbstractClient client, FileMetaData meta, byte[] data)

Save a file into the file cache

Parameters
client the current client
meta the filemetadata associated with the file
data the data of the file to write to disk

public void trimCache (Context context)

This method compares the current size of all files in the cache dir to the limit size. If there are too many files, an async task will be kicked off to delete older files.

Parameters
context - the current application's context