Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/simple-db-cache
Simple Db Cache based on mtime.
https://github.com/thlorenz/simple-db-cache
Last synced: 26 days ago
JSON representation
Simple Db Cache based on mtime.
- Host: GitHub
- URL: https://github.com/thlorenz/simple-db-cache
- Owner: thlorenz
- Created: 2021-02-23T21:13:27.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-24T15:33:53.000Z (almost 4 years ago)
- Last Synced: 2024-10-23T06:14:49.020Z (2 months ago)
- Language: TypeScript
- Size: 24.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-db-cache [![](https://github.com/thlorenz/simple-db-cache/workflows/Node/badge.svg?branch=master)](https://github.com/thlorenz/simple-db-cache/actions)
Simple Db Cache based on mtime.
## Example
```typescript
import path from 'path'
import { strict as assert } from 'assert'
import { SimpleDbCache } from 'simple-db-cache'
function doMyThing(projectRoot: string) {
const dirtSimpleDbCache = SimpleDbCache.initSync({
useMemoryCache: true,
hydrateMemoryCache: true,
})
const foo = path.join(projectRoot, '/some/file/foo.ts')
const bar = path.join(projectRoot, '/some/file/bar.ts')const converted = convertMyFile(foo)
dirtSimpleDbCache.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.
## In Memory Cache
When `useMemoryCache` is set files will be kept in memory after they are
fetched from the Database for the next use.When `hydrateMemoryCache` is set all files will be fetched from the
database via a `SELECT * ...` query and stored in memory. This is a lot faster
than querying for each file, but comes at the cost of a higher memory
footprint.When `evictMemoryOnRead` is set then entries are removed from the in memory cache when the are
retrieved the same time. Additionally if they are retrieved from the database they are NOT
added to the in memory cache.## LICENSE
MIT