Tankōbon / main/services/thumbnail-cache / ThumbnailCache
Class: ThumbnailCache
Defined in: main/services/thumbnail-cache.ts:54
The thumbnail cache directory. Every generation goes through a single queue, one book at a time: a library page asking for hundreds of covers at once, or a rebuild after an import, must not open hundreds of archives in parallel. Concurrent requests for the same book share one generation.
Constructors
Constructor
new ThumbnailCache(
directory,open?):ThumbnailCache
Defined in: main/services/thumbnail-cache.ts:60
Parameters
directory
string
open?
(filePath) => Promise<ComicArchive>
Returns
ThumbnailCache
Methods
ensure()
ensure(
filePath,readFirstPage?):Promise<Uint8Array<ArrayBuffer> |null>
Defined in: main/services/thumbnail-cache.ts:79
The thumbnail of a book, generated and cached first when missing. readFirstPage reads the cover from an archive that is already open (the reader's); without it, the file is opened just for this. Resolves to null when the book has no image page or can't be read.
Parameters
filePath
string
readFirstPage?
() => Promise<ComicPage>
Returns
Promise<Uint8Array<ArrayBuffer> | null>
prune()
prune(
filePaths):Promise<void>
Defined in: main/services/thumbnail-cache.ts:123
Deletes every cached file that isn't the thumbnail of one of filePaths, including temporary files left by a crash. Queued like a generation, so it never deletes one being written.
Parameters
filePaths
readonly string[]
Returns
Promise<void>
read()
read(
filePath):Promise<Uint8Array<ArrayBuffer> |null>
Defined in: main/services/thumbnail-cache.ts:66
The cached thumbnail of a book, or null when there is none yet. Never generates one.
Parameters
filePath
string
Returns
Promise<Uint8Array<ArrayBuffer> | null>
rebuild()
rebuild(
filePaths):Promise<void>
Defined in: main/services/thumbnail-cache.ts:144
Brings the cache in line with the library after a JSON import: drops the thumbnails of books no longer listed, then generates the missing ones, one book at a time, giving earlier failures a new chance. Requests made meanwhile (the library page) take their turn between two books instead of waiting for the whole rebuild.
Parameters
filePaths
readonly string[]
Returns
Promise<void>
remove()
remove(
filePath):Promise<void>
Defined in: main/services/thumbnail-cache.ts:112
Deletes the thumbnail of a book (removed from the library); does nothing when there is none. Queued like a generation, so one still running for this book finishes first and its file is deleted too, instead of being written after the deletion and left orphaned.
Parameters
filePath
string
Returns
Promise<void>
storeFromArchive()
storeFromArchive(
archive):Promise<void>
Defined in: main/services/thumbnail-cache.ts:100
Generates the thumbnail of a book from an archive the caller has open (a folder scan), unless it is already cached. Never throws: a book without a cover only goes without a thumbnail.
Parameters
archive
Returns
Promise<void>