-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added cache revalidation API integration
- Loading branch information
1 parent
9bad2ed
commit 4ba4741
Showing
9 changed files
with
94 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Injectable, Inject, CACHE_MANAGER } from '@nestjs/common'; | ||
import { Cache } from 'cache-manager'; | ||
import axios from 'axios'; | ||
import { LogService } from '../../shared/log.service'; | ||
|
||
@Injectable() | ||
export class CacheService { | ||
constructor( | ||
@Inject(CACHE_MANAGER) private cache: Cache, | ||
private logService: LogService | ||
) {} | ||
|
||
// Mapping service names to tags | ||
private serviceTagsMap = { | ||
members: ['member-filters', 'member-list'], | ||
projects: ['project-list', 'focus-areas'], | ||
teams: ['team-filters', 'team-list', 'focus-areas'], | ||
}; | ||
|
||
// Reset cache and call API based on service | ||
async reset(data) { | ||
const { service } = data; | ||
await this.cache.reset(); // Reset the cache | ||
const tags = this.serviceTagsMap[service]; | ||
if (tags) { | ||
await this.revalidateCache(tags); | ||
} | ||
} | ||
|
||
// Function to call the revalidate API | ||
private async revalidateCache(tags: string[]) { | ||
const baseUrl = process.env.WEB_UI_BASE_URL; | ||
const token = process.env.REVALIDATE_API_TOKEN; // Assuming token is stored in env variable | ||
if (!baseUrl) { | ||
this.logService.error('WEB_UI_BASE_URL is not defined in the environment variables.'); | ||
return; | ||
} | ||
if (!token) { | ||
this.logService.error('REVALIDATE_API_TOKEN is not defined in the environment variables.'); | ||
return; | ||
} | ||
const url = `${baseUrl}/api/revalidate`; | ||
try { | ||
await axios.post( | ||
url, | ||
{ tags }, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${token}`, // Adding Bearer token to headers | ||
}, | ||
}, | ||
); | ||
this.logService.info(`Revalidation API called successfully with tags: ${tags.join(', ')}`); | ||
} catch (error) { | ||
this.logService.error('Error calling revalidate API:', error.message); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.