|
import sqlite3 from 'sqlite3'; |
|
import sqliteStore from 'cache-manager-sqlite'; |
|
import cacheManager from 'cache-manager'; |
|
import config from './config.js'; |
|
import {wait} from './util.js'; |
|
|
|
const db = new sqlite3.Database(`${config.dataFolder}/cache.db`); |
|
|
|
const cache = await cacheManager.caching({ |
|
store: sqliteStore, |
|
path: `${config.dataFolder}/cache.db`, |
|
options: { ttl: 86400 } |
|
}); |
|
|
|
export default cache; |
|
|
|
export async function clean(){ |
|
|
|
|
|
|
|
await cache.set('_clean', 'todo', {ttl: 1}); |
|
await wait(3e3); |
|
await cache.get('_clean'); |
|
} |
|
|
|
export async function vacuum(){ |
|
return new Promise((resolve, reject) => { |
|
db.serialize(() => { |
|
db.run('VACUUM', err => { |
|
if(err)return reject(err); |
|
resolve(); |
|
}) |
|
}); |
|
}); |
|
} |