import { Datastore , DatastoreID , ErrorListener , InitResult } from './Datastore' ; import { BinaryFileData } from './Datastore' ; import { WriteFileOpts } from './Datastore' ; import { isBinaryFileData } from './Datastore' ; import { DocMetaRef } from './DocMetaRef' ; import { DiskDatastore } from './DiskDatastore' ; import { RemoteDatastore } from './RemoteDatastore' ; import { Backend } from 'polar-shared/src/datastore/Backend' ; import { DocFileMeta } from 'polar-shared/src/datastore/DocFileMeta' ; import { Blobs } from 'polar-shared/src/util/Blobs' ; import { Optional } from 'polar-shared/src/util/ts/Optional' ; import { Logger } from 'polar-shared/src/logger/Logger' ; import { DatastoreFileCache } from './DatastoreFileCache' ; import { DelegatedDatastore } from './DelegatedDatastore' ; import { FileRef } from "polar-shared/src/datastore/FileRef" ; import { GetFileOpts } from "polar-shared/src/datastore/IDatastore" ; const log = Logger . create ( ) ; /**
 * Basic delegated datastore so that we can resolve files form the local file
 * cache before going to the network version.
 */ export class DataFileCacheDatastore extends DelegatedDatastore { constructor ( delegate ) { super ( delegate ) ; } public getFile ( backend , ref , opts ? ) { const hit = DatastoreFileCache . getFile ( backend , ref ) ; if ( hit . isPresent ( ) ) { log . debug ( "Found file in datastore cache: " , { backend , ref } ) ; return hit . get ( ) ; } return super . getFile ( backend , ref , opts ) ; } public async deleteFile ( backend , ref ) { DatastoreFileCache . evictFile ( backend , ref ) ; return super . deleteFile ( backend , ref ) ; } }