Files
lib/src/orm/support/CacheModel.ts
garrettmills 074a3187eb
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is failing
Add support for jobs & queueables, migrations
- Create migration directives & migrators
- Modify Cache classes to support array manipulation
- Create Redis unit and RedisCache implementation
- Create Queueable base class and Queue class that uses Cache backend
2021-08-23 23:51:53 -05:00

35 lines
1007 B
TypeScript

import {Model} from '../model/Model'
import {Field} from '../model/Field'
import {FieldType} from '../types'
import {Maybe} from '../../util'
import {ModelBuilder} from '../model/ModelBuilder'
/**
* A model instance which stores records from the ORMCache driver.
*/
export class CacheModel extends Model<CacheModel> {
protected static table = 'caches'; // FIXME allow configuring
protected static key = 'cache_key';
@Field(FieldType.varchar, 'cache_key')
public cacheKey!: string;
@Field(FieldType.text, 'cache_value')
public cacheValue!: string;
@Field(FieldType.timestamp, 'cache_expires')
public cacheExpires?: Date;
public static withCacheKey(key: string): ModelBuilder<CacheModel> {
return this.query<CacheModel>()
.whereKey(key)
.whereProperty('cacheExpires', '>', new Date())
}
public static getCacheKey(key: string): Promise<Maybe<CacheModel>> {
return this.withCacheKey(key)
.first()
}
}