-
Notifications
You must be signed in to change notification settings - Fork 130
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
refactor(cache): improve caching system and add expiring cache #408
base: main
Are you sure you want to change the base?
Conversation
hey! thanks for the PR! can you merge with main? thanks! |
With this approach, I was able to shave off ~1.2s in each request
… cache Using a standard error type (os.ErrNotExist) instead of a custom error message ("cache expired") makes the error handling more consistent with Go conventions and allows for better error checking using errors.Is().
- Add error handling for file removal operations - Properly handle file.Close() errors using defer functions
- Add package-level documentation for cache types and constants - Document public methods and types with descriptive comments - Reorganize constant and variable declarations
473e6a4
to
9cb7116
Compare
- Use os.ModePerm constant for directory creation - Add clarifying constant for filename format validation - Fix documentation periods consistency - Improve code spacing
- Add descriptive error messages with wrapping - Use context in HTTP requests - Improve error handling in HTTP responses
f10dfb3
to
f2bcdd5
Compare
Done! Sorry for the Had some conflicts with main in my fork and had to rebase my commits to make it work. Also added a wrapper around the errors and fixed some minor linting issues. If you need me to change anything, just let me know. |
} | ||
|
||
func (c *convoCache) read(id string, messages *[]openai.ChatCompletionMessage) error { | ||
func (c *Cache[T]) cacheDir() string { |
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.
func (c *Cache[T]) cacheDir() string { | |
func (c *Cache[T]) dir() string { |
no nead to repeat cache I think
Description
For my usage which primarily uses Copilot, this change made a huge difference in performance - reducing about ~2 seconds for each request by caching the access tokens.
Not sure if this is the direction you want to go, but I found it very helpful for my workflow.
Let me know if you'd like any changes - happy to update!
Changes
Convert existing cache to generic Cache[T] type
Add ExpiringCache implementation
Note: This PR builds on #406 and should be merged after it.