fix cache bug

pull/152/merge
Bosn 7 years ago
parent 3e0e3afde5
commit 43fd092dfd

@ -22,7 +22,7 @@ let config: IConfigOptions = {
idle: 20000,
acquire: 20000,
},
logging: true
logging: false
},
redis: {}
}

@ -1,4 +1,4 @@
import { Table, Column, Model, HasMany, AutoIncrement, PrimaryKey, AllowNull, DataType, Default, BelongsTo, ForeignKey, AfterUpdate, AfterBulkUpdate } from 'sequelize-typescript'
import { Table, Column, Model, HasMany, AutoIncrement, PrimaryKey, AllowNull, DataType, Default, BelongsTo, ForeignKey, BeforeBulkDelete, BeforeBulkCreate, BeforeBulkUpdate, BeforeCreate, BeforeUpdate, BeforeDelete } from 'sequelize-typescript'
import { User, Module, Repository, Property } from '../';
import RedisService, { CACHE_KEY } from '../../service/redis'
@ -8,14 +8,21 @@ enum methods { GET= 'GET', POST= 'POST', PUT= 'PUT', DELETE= 'DELETE' }
export default class Interface extends Model<Interface> {
/** hooks */
@AfterUpdate
@BeforeCreate
@BeforeUpdate
@BeforeDelete
static async deleteCache(instance: Interface) {
await RedisService.delCache(CACHE_KEY.REPOSITORY_GET, instance.repositoryId)
}
@AfterBulkUpdate
@BeforeBulkCreate
@BeforeBulkUpdate
@BeforeBulkDelete
static async bulkDeleteCache(options: any) {
const id = options && options.attributes && options.attributes.id
let id: number = options && options.attributes && options.attributes.id
if (!id) {
id = options.where && +options.where.id
}
if (id) {
const itf = await Interface.findById(id)
await RedisService.delCache(CACHE_KEY.REPOSITORY_GET, itf.repositoryId)

@ -1,4 +1,4 @@
import { Table, Column, Model, HasMany, AutoIncrement, PrimaryKey, AllowNull, DataType, Default, BelongsTo, BelongsToMany, ForeignKey, BeforeUpdate, AfterBulkUpdate } from 'sequelize-typescript'
import { Table, Column, Model, HasMany, AutoIncrement, PrimaryKey, AllowNull, DataType, Default, BelongsTo, BelongsToMany, ForeignKey, BeforeUpdate, BeforeCreate, BeforeDelete, BeforeBulkCreate, BeforeBulkUpdate, BeforeBulkDelete } from 'sequelize-typescript'
import { User, Organization, Module, Interface, RepositoriesCollaborators } from '../'
import RedisService, { CACHE_KEY } from '../../service/redis'
@ -6,12 +6,16 @@ import RedisService, { CACHE_KEY } from '../../service/redis'
export default class Repository extends Model<Repository> {
/** hooks */
@BeforeCreate
@BeforeUpdate
@BeforeDelete
static async cleanCache(instance: Repository) {
await RedisService.delCache(CACHE_KEY.REPOSITORY_GET, instance.id)
}
@AfterBulkUpdate
@BeforeBulkCreate
@BeforeBulkUpdate
@BeforeBulkDelete
static async bulkDeleteCache(options: any) {
const id = options && options.attributes && options.attributes.id
if (id) {

Loading…
Cancel
Save