Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
josephaxisa committed Apr 12, 2023
1 parent ab514c7 commit cb13a6c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/embed-services/src/ItemList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ describe('ItemList', () => {
it('returns undefined if item not found', () => {
const actual = ItemList.find('name', 'bogus')
expect(actual).toBeUndefined()

expect(ItemList.find('name', 'barName')).toEqual(items[1])
})
})

describe('getCacheDefault', () => {
it('gets the default', () => {
const actual = ItemList.getCacheDefault()
expect(actual).toBe(true)
})

it('gets value from itemCache option when specified', () => {
const actual = ItemList.getCacheDefault({ itemCache: false })
expect(actual).toBe(false)
})
})
})
16 changes: 15 additions & 1 deletion packages/embed-services/src/ItemList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import { EntityService } from './EntityService'

export const DEFAULT_TTL = 900 // 15 minutes

export interface GetOptions {
itemCache?: boolean
[key: string]: any
}

export interface IItemList<T> {
/** Cache time to live in seconds, defaults to 15 minutes */
readonly timeToLive: number
Expand All @@ -42,7 +47,7 @@ export interface IItemList<T> {
}

export interface IEntityService<T> extends IItemList<T> {
get(id: string, cache?: boolean, ...options: any[]): Promise<T>
get(id: string, options?: GetOptions): Promise<T>
set(id: string, item: T): Promise<T>
getAll(...options: any[]): Promise<IItemList<T>>
delete(id: string): void
Expand Down Expand Up @@ -111,4 +116,13 @@ export abstract class ItemList<T extends Record<string, any>>
| T
| undefined
}

/**
* Gets the cache option value if present, otherwise defaults to true
* @param options to check
*/
getCacheDefault(options?: GetOptions) {
const cache = options && 'itemCache' in options ? options.itemCache : true
return cache
}
}

0 comments on commit cb13a6c

Please sign in to comment.