0.4.0 • Published 3 years ago

dirt-simple-file-cache v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

dirt-simple-file-cache npm.io

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

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.0

3 years ago