Skip to content

Commit

Permalink
feat: cache-link invalidate cache with invalidateCache option
Browse files Browse the repository at this point in the history
  • Loading branch information
achamorro-dev committed Nov 29, 2022
1 parent 2cfcd2f commit cdf5b6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/arch/src/runner/links/cache-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('CacheLink', () => {
verify(link.next(anything())).once()
})

it("should not use the cache when 'invalidateCache' flag is true", async () => {
it("should invalidate the cache when 'invalidateCache' flag is true", async () => {
const { link, cacheManager, cacheLink } = setup()

class MockUseCase extends UseCase<unknown, unknown> {
Expand All @@ -50,7 +50,7 @@ describe('CacheLink', () => {
await cacheLink.next(context)

verify(link.next(anything())).once()
verify(cacheManager.has(anything(), anything())).never()
verify(cacheManager.invalidate(anything())).once()
})

it('should break the link if it is cached', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/arch/src/runner/links/cache-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export class CacheLink extends BaseLink {
const asClass = context.useCase as unknown as UseCase
const useCaseKey = asClass.key

if (context.executionOptions.invalidateCache || !this.cacheManager.has(useCaseKey, [context.param])) {
if (context.executionOptions.invalidateCache) {
this.cacheManager.invalidate(useCaseKey)
}

if (!this.cacheManager.has(useCaseKey, [context.param])) {
this.nextLink.next(context)
}

Expand Down

0 comments on commit cdf5b6d

Please sign in to comment.