Skip to content

Commit

Permalink
refactor: avoid redundancy of cache events
Browse files Browse the repository at this point in the history
  • Loading branch information
Melchyore committed May 1, 2023
1 parent 72e9bad commit aedabb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions adonis-typings/cache-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ declare module '@ioc:Adonis/Addons/Cache' {
expiration?: number
}

export enum CacheEvents {
Hit = 'cache:hit',
Missed = 'cache:missed',
KeyWritten = 'cache:key_written',
KeyForgotten = 'cache:key_forgotten'
}
export type CacheEvents = import('../src/Enums/CacheEvents').default

export interface CacheEventContract extends CacheEventPayload {
EVENT: CacheEvents
Expand All @@ -24,14 +19,18 @@ declare module '@ioc:Adonis/Addons/Cache' {
}

declare module '@ioc:Adonis/Core/Event' {
import type { CacheEventPayload, CacheClearEventPayload } from '@ioc:Adonis/Addons/Cache'
import type {
CacheEventPayload,
CacheClearEventPayload,
CacheEvents
} from '@ioc:Adonis/Addons/Cache'

export interface EventsList {
'cache:hit': CacheEventPayload
'cache:missed': CacheEventPayload
'cache:key_written': CacheEventPayload
'cache:key_forgotten': CacheEventPayload
type Events = {
[E in 'CacheEvents']: CacheEventPayload
} & {
'cache:clearing': CacheClearEventPayload
'cache:cleared': CacheClearEventPayload
}

export interface EventsList extends Events {}
}
2 changes: 1 addition & 1 deletion src/Enums/CacheEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum CacheEvents {
enum CacheEvents {
Hit = 'cache:hit',
Missed = 'cache:missed',
KeyWritten = 'cache:key_written',
Expand Down

0 comments on commit aedabb2

Please sign in to comment.