-
Notifications
You must be signed in to change notification settings - Fork 1
[FE] 교수 유저 데이터 캐싱 추가 #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FE] 교수 유저 데이터 캐싱 추가 #214
Conversation
WalkthroughThe changes enhance the professor data management in the repository by introducing a caching mechanism. The Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant PR as ProfessorRepository
participant API as External API
C->>PR: getProfessor()
alt Cache available
PR-->>C: Return cached professor data
else Cache empty
PR->>API: Fetch professor data
API-->>PR: Return professor data
PR->>PR: Update ProfessorCache
PR-->>C: Return fetched data
end
Suggested Reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
front-end/src/repository/professorRepository.ts (3)
5-5: Follow TypeScript naming conventions for private properties.Rename
ProfessorCachetoprofessorCacheto follow TypeScript naming conventions for private properties (camelCase).- private ProfessorCache: Professor | null = null; + private professorCache: Professor | null = null;
41-43: Consider implementing a cache invalidation strategy.While the cache implementation is correct, consider adding:
- Time-to-live (TTL) for cache entries
- Cache invalidation on error responses
- Cache refresh mechanism for stale data
This helps prevent serving stale data and manages memory efficiently.
Example implementation:
interface CachedProfessor extends Professor { timestamp: number; } private professorCache: CachedProfessor | null = null; private readonly CACHE_TTL = 5 * 60 * 1000; // 5 minutes private isCacheValid(): boolean { return this.professorCache && (Date.now() - this.professorCache.timestamp) < this.CACHE_TTL; }Also applies to: 67-69
127-131: Refactor cache updates to reduce duplication and improve type safety.The cache update logic is duplicated and could be simplified. Also, consider adding type guards for API responses.
private updateCache(partial: Partial<Professor>): void { this.professorCache = { name: '', email: '', profileURL: '', ...this.professorCache, ...partial, }; } // Usage in updateProfessorName: this.updateCache({ name: json.data.name.toString() }); // Usage in updateProfessorProfile: this.updateCache({ profileURL: json.data.imageUrl.toString() });Also applies to: 156-160
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
front-end/src/repository/professorRepository.ts(7 hunks)
🔇 Additional comments (1)
front-end/src/repository/professorRepository.ts (1)
4-181: Overall implementation looks good with suggested improvements.The caching implementation successfully reduces API calls and improves performance. The suggested improvements around naming conventions, cache invalidation, error handling, and code reusability will make the implementation more robust and maintainable.
|
|
||
| await throwError(response); | ||
|
|
||
| this.ProfessorCache = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve error handling for cache clearing operations.
Move cache clearing after successful response handling to prevent cache inconsistency if the API call fails.
// In logout method
- await throwError(response);
- this.professorCache = null;
+ await throwError(response);
if (response.redirected) {
+ this.professorCache = null;
window.location.href = response.url;
}
+ this.professorCache = null;
// In deleteProfessor method
- await throwError(response);
- this.professorCache = null;
+ await throwError(response);
if (response.redirected) {
+ this.professorCache = null;
window.location.href = response.url;
}
+ this.professorCache = null;Also applies to: 175-175
wwweric12
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
캐싱하는거 좋은거 같습니다! 고생하셨습니다!
#️⃣ 연관된 이슈
📝 작업 내용
Summary by CodeRabbit