Skip to content

Commit

Permalink
cache cleared when user updating profile
Browse files Browse the repository at this point in the history
  • Loading branch information
abinth11 committed Aug 30, 2023
1 parent 72e838a commit 3e4e130
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/src/adapters/controllers/studentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const studentController = (
cloudService,
dbRepositoryStudent
);
await dbRepositoryCache.clearCache(studentId ?? '');
res.status(200).json({
status: 'success',
message: 'Successfully updated your profile',
Expand Down
5 changes: 4 additions & 1 deletion server/src/app/repositories/cachedRepoInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ export const cacheRepositoryInterface=(repository:ReturnType<RedisRepositoryImpl
data: string;
})=>await repository.setCache(cachingOptions)

const clearCache = async(key:string)=> await repository.clearCache(key)

return {
setCache
setCache,
clearCache
}

}
Expand Down
7 changes: 7 additions & 0 deletions server/src/frameworks/database/redis/redisCacheRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CourseInterface } from '@src/types/courseInterface';
import { RedisClient } from '../../../app';

export function redisCacheRepository(redisClient: RedisClient) {

const setCache = async ({
key,
expireTimeSec,
Expand All @@ -12,6 +13,11 @@ export function redisCacheRepository(redisClient: RedisClient) {
data: string;
}) => await redisClient.setEx(key, expireTimeSec, data);

const clearCache = async (key: string) => {
const result = await redisClient.del(key);
return result === 1;
};

const populateTrie = async (course: CourseInterface) => {
const trie: { [key: string]: any } = {}; // Initialize the trie object

Expand All @@ -31,6 +37,7 @@ export function redisCacheRepository(redisClient: RedisClient) {

return {
setCache,
clearCache,
populateTrie
};
}
Expand Down

0 comments on commit 3e4e130

Please sign in to comment.