mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-04-19 21:03:56 +02:00
Rename existing cache model
This commit is contained in:
parent
381ee62b78
commit
d805da906a
4 changed files with 8 additions and 8 deletions
|
@ -1,9 +1,9 @@
|
||||||
import Cache from './cache.js';
|
import KeyValueCache from './key-value-cache.js';
|
||||||
import Settings from './settings.js';
|
import Settings from './settings.js';
|
||||||
import Shortcut from './shortcut.js';
|
import Shortcut from './shortcut.js';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Cache,
|
KeyValueCache,
|
||||||
Settings,
|
Settings,
|
||||||
Shortcut,
|
Shortcut,
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {Table, Column, PrimaryKey, Model} from 'sequelize-typescript';
|
||||||
import sequelize from 'sequelize';
|
import sequelize from 'sequelize';
|
||||||
|
|
||||||
@Table
|
@Table
|
||||||
export default class Cache extends Model<Cache> {
|
export default class KeyValueCache extends Model<KeyValueCache> {
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
@Column
|
@Column
|
||||||
key!: string;
|
key!: string;
|
|
@ -1,5 +1,5 @@
|
||||||
import {injectable} from 'inversify';
|
import {injectable} from 'inversify';
|
||||||
import {Cache} from '../models/index.js';
|
import {KeyValueCache} from '../models/index.js';
|
||||||
import debug from '../utils/debug.js';
|
import debug from '../utils/debug.js';
|
||||||
|
|
||||||
type Seconds = number;
|
type Seconds = number;
|
||||||
|
@ -29,7 +29,7 @@ export default class CacheProvider {
|
||||||
throw new Error(`Cache key ${key} is too short.`);
|
throw new Error(`Cache key ${key} is too short.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachedResult = await Cache.findByPk(key);
|
const cachedResult = await KeyValueCache.findByPk(key);
|
||||||
|
|
||||||
if (cachedResult) {
|
if (cachedResult) {
|
||||||
if (new Date() < cachedResult.expiresAt) {
|
if (new Date() < cachedResult.expiresAt) {
|
||||||
|
@ -45,7 +45,7 @@ export default class CacheProvider {
|
||||||
const result = await func(...options as any[]);
|
const result = await func(...options as any[]);
|
||||||
|
|
||||||
// Save result
|
// Save result
|
||||||
await Cache.upsert({
|
await KeyValueCache.upsert({
|
||||||
key,
|
key,
|
||||||
value: JSON.stringify(result),
|
value: JSON.stringify(result),
|
||||||
expiresAt: futureTimeToDate(expiresIn),
|
expiresAt: futureTimeToDate(expiresIn),
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import {Sequelize} from 'sequelize-typescript';
|
import {Sequelize} from 'sequelize-typescript';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {DATA_DIR} from '../services/config.js';
|
import {DATA_DIR} from '../services/config.js';
|
||||||
import {Cache, Settings, Shortcut} from '../models/index.js';
|
import {KeyValueCache, Settings, Shortcut} from '../models/index.js';
|
||||||
|
|
||||||
export const sequelize = new Sequelize({
|
export const sequelize = new Sequelize({
|
||||||
dialect: 'sqlite',
|
dialect: 'sqlite',
|
||||||
database: 'muse',
|
database: 'muse',
|
||||||
storage: path.join(DATA_DIR, 'db.sqlite'),
|
storage: path.join(DATA_DIR, 'db.sqlite'),
|
||||||
models: [Cache, Settings, Shortcut],
|
models: [KeyValueCache, Settings, Shortcut],
|
||||||
logging: false,
|
logging: false,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue