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

cache is overwritten even when not changed #25

Closed
cu opened this issue Aug 26, 2023 · 2 comments
Closed

cache is overwritten even when not changed #25

cu opened this issue Aug 26, 2023 · 2 comments

Comments

@cu
Copy link

cu commented Aug 26, 2023

This is a very nice tool, thank you! I hope to use it to replace my own home-grown version of roughly the same thing.

One thing I noticed is that the cache file ~/.cache/cloudflare-dyndns/ip.cache gets overwritten on every invocation of the program, even if nothing has changed. It's just a few hundred bytes, yes, but on flash storage this equates to at least a 4kB or more write depending on the hardware and filesystem. In the grand scheme of things, very likely not a big deal, but it would be nice to do the right thing if possible.

I haven't had the time to fully understand the flow of things, but two approaches that I can think of:

  1. Track changes to the cache somehow and mark the cache as "dirty" when a value is written. Then, only write when the cache is dirty.
  2. Before writing the cache file, read the existing file and compare the JSON. Only trigger a write when they differ.

One workaround for those who are concerned about unnecessary writes could be to store the cache file on a RAM-backed filesystem, e.g. /dev/shm/ip.cache.

@cu cu changed the title overwrite cache only when changed cache is ovewritten even when not changed Aug 26, 2023
@cu cu changed the title cache is ovewritten even when not changed cache is overwritten even when not changed Aug 26, 2023
@kissgyorgy
Copy link
Owner

kissgyorgy commented Aug 26, 2023

You are right. I fixed it: https://github.com/kissgyorgy/cloudflare-dyndns/releases/tag/v5.0beta5
You can install with pip: pip install cloudflare-dyndns==5.0b5

@cu
Copy link
Author

cu commented Aug 28, 2023

Wow, that was fast! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants