-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: LRU cache for dependencies #98
Conversation
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.
Currently the config takes the max. size in bytes. I would prefer if the user could supply a "size string", i.e. "100M" or "10G" like some Unix tools allow to. Would make it easier to configure, what do you think?
As discussed in person, having a quick, little parsing step for M
&G
suffixed parameters sounds reasonable.
In a follow-up PR we can also abstract the cache and re-use it e.g. for object file caching.
This would be awesome, yeah! 🚀
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.
Nice! 👍
homcc/server/cache.py
Outdated
""" | ||
oldest_hash, oldest_path_str = self.cache.popitem(last=False) | ||
oldest_path = Path(oldest_path_str) | ||
oldest_size = oldest_path.stat().st_size |
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.
If the file does not exist, isn't this going to raise an exception?
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.
Very good point! This also affects cache size calculation. I moved the stat
call into the try block, and adjusted the log message that the cache size calculation may be wrong if files are deleted by other processes.
A different solution would be to store the size of each cache entry in memory, but I don't really like that. In the end, some cache entries being deleted by other processes are probably rather very much an edge case, so I guess handling it like this is fine.
Implements an LRU eviction for the dependency cache. Cache size can be configured, and is per default 10G.
In a follow-up PR we can also abstract the cache and re-use it e.g. for object file caching.