Skip to content

cypress-io/dirt-simple-file-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dirt-simple-file-cache

Dirt Simple File Cache based on mtime.

Example

import path from 'path'
import { strict as assert } from 'assert'
import { DirtSimpleFileCache } from 'dirt-simple-file-cache'
  
function async doMyThing(projectRoot: string) {
  const dirtSimpleFileCache = await DirtSimpleFileCache.init(projectRoot)
  
  // Clear cache f you want to start fresh 
  await dirtSimpleFileCache.clear()

  const foo = path.join(projectRoot, '/some/file/foo.ts')
  const bar = path.join(projectRoot, '/some/file/bar.ts')

  const converted = convertMyFile(foo)
  dirtSimpleFileCache.add(foo, converted)
  
  const cachedFoo = dirtSimpleFileCache.get(foo)
  const cachedBar = dirtSimpleFileCache.get(bar)
  
  assert(cachedFoo === converted)
  assert(cachedBar == null)
}

The above works across runs as the cache is persisted to a tmp folder.

Extra Features

If keepInMemoryCache: true is passed as opts then an in memory cache is used. This cache is not checked for staleness.

For the file cache mtimes are compared via fs operations and cached content is retrieved the same way.

Therefore it is advisable to not keep an in memory cache if you expect your original assets to change while the program is running.

LICENSE

MIT

About

Dirt Simple File Cache based on mtime.

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published