|
|
|
@ -24,29 +24,14 @@ import java.io.IOException
|
|
|
|
|
* The files are in format *md5key*.0
|
|
|
|
|
*
|
|
|
|
|
* @param context the application context.
|
|
|
|
|
* @constructor creates an instance of the chapter cache.
|
|
|
|
|
*/
|
|
|
|
|
class ChapterCache(private val context: Context) {
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
/** Name of cache directory. */
|
|
|
|
|
const val PARAMETER_CACHE_DIRECTORY = "chapter_disk_cache"
|
|
|
|
|
|
|
|
|
|
/** Application cache version. */
|
|
|
|
|
const val PARAMETER_APP_VERSION = 1
|
|
|
|
|
|
|
|
|
|
/** The number of values per cache entry. Must be positive. */
|
|
|
|
|
const val PARAMETER_VALUE_COUNT = 1
|
|
|
|
|
|
|
|
|
|
/** The maximum number of bytes this cache should use to store. */
|
|
|
|
|
const val PARAMETER_CACHE_SIZE = 100L * 1024 * 1024
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val json: Json by injectLazy()
|
|
|
|
|
|
|
|
|
|
/** Cache class used for cache management. */
|
|
|
|
|
/** Cache class used for cache management. */
|
|
|
|
|
private val diskCache = DiskLruCache.open(
|
|
|
|
|
File(context.cacheDir, PARAMETER_CACHE_DIRECTORY),
|
|
|
|
|
File(context.cacheDir, "chapter_disk_cache"),
|
|
|
|
|
PARAMETER_APP_VERSION,
|
|
|
|
|
PARAMETER_VALUE_COUNT,
|
|
|
|
|
PARAMETER_CACHE_SIZE,
|
|
|
|
@ -55,8 +40,7 @@ class ChapterCache(private val context: Context) {
|
|
|
|
|
/**
|
|
|
|
|
* Returns directory of cache.
|
|
|
|
|
*/
|
|
|
|
|
private val cacheDir: File
|
|
|
|
|
get() = diskCache.directory
|
|
|
|
|
private val cacheDir: File = diskCache.directory
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns real size of directory.
|
|
|
|
@ -210,3 +194,12 @@ class ChapterCache(private val context: Context) {
|
|
|
|
|
return "${chapter.mangaId}${chapter.url}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Application cache version. */
|
|
|
|
|
private const val PARAMETER_APP_VERSION = 1
|
|
|
|
|
|
|
|
|
|
/** The number of values per cache entry. Must be positive. */
|
|
|
|
|
private const val PARAMETER_VALUE_COUNT = 1
|
|
|
|
|
|
|
|
|
|
/** The maximum number of bytes this cache should use to store. */
|
|
|
|
|
private const val PARAMETER_CACHE_SIZE = 100L * 1024 * 1024
|
|
|
|
|