Skip to content
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

Added the cache_file decorator #221

Merged
merged 9 commits into from
May 7, 2024
Merged

Conversation

YHordijk
Copy link
Contributor

This decorator will cache results from function calls and save them to a file locally. This is usefull for functions that are very expensive to run or require the user to be online. Previous results can then be used if the user is offline.

@YHordijk YHordijk linked an issue Apr 29, 2024 that may be closed by this pull request
@YHordijk YHordijk self-assigned this Apr 29, 2024
@YHordijk YHordijk requested a review from SiebeLeDe April 29, 2024 22:33
@YHordijk YHordijk added the enhancement New feature or request label Apr 29, 2024
@YHordijk YHordijk marked this pull request as ready for review April 30, 2024 06:15
YHordijk added a commit that referenced this pull request Apr 30, 2024
Copy link
Contributor

@SiebeLeDe SiebeLeDe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To which location is the cached file written to? I know from computer scientists that there is a certain folder called "/tmp" which is the default folder for cached files and temporary files.

However, this is OS dependent.

Windows: C:\Users\AppData\Local\Temp
Mac: ~/Library/Caches/

@YHordijk
Copy link
Contributor Author

YHordijk commented May 6, 2024

The function will create a directory called .cached in the tcutility src directory. There it will be stored as the name given by the user. Would it be better to store it in the correct caching directory?

@SiebeLeDe
Copy link
Contributor

I think it's better to do it in the designated caching directory. I saw this through searching that could help. There is already a python package that deals with temp files called tempfile. Check especially the NamedTempFile where you can give it a name and say if it should be deleted.

This causes you yourself not having to deal with os dependent stuff

@YHordijk YHordijk requested a review from SiebeLeDe May 7, 2024 15:24
@YHordijk
Copy link
Contributor Author

YHordijk commented May 7, 2024

I think it's better to do it in the designated caching directory. I saw this through searching that could help. There is already a python package that deals with temp files called tempfile. Check especially the NamedTempFile where you can give it a name and say if it should be deleted.

This causes you yourself not having to deal with os dependent stuff

We now use the platformdirs module to deal with this.

@YHordijk YHordijk merged commit da70ba4 into main May 7, 2024
1 check passed
@YHordijk YHordijk deleted the 220-store-cached-results-locally branch May 7, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store cached results locally
2 participants