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

Store time of last modified in cache dir #2368

Merged
merged 4 commits into from
Jul 17, 2024

Conversation

afbjorklund
Copy link
Member

@afbjorklund afbjorklund commented May 27, 2024

Was looking more at caching, and thought it would be a good idea to store the last modified time too.

$ more ~/.cache/lima/download/by-url-sha256/2385cd7cc68589b1dab56df12415b9151d977ba9b9b668e913f02ebd35804ef7/url 
https://github.com/lima-vm/alpine-lima/releases/download/v0.2.38/alpine-lima-std-3.19.0-x86_64.iso
$ more ~/.cache/lima/download/by-url-sha256/2385cd7cc68589b1dab56df12415b9151d977ba9b9b668e913f02ebd35804ef7/time 
Fri, 26 Apr 2024 05:04:22 GMT
$ more ~/.cache/lima/download/by-url-sha256/2385cd7cc68589b1dab56df12415b9151d977ba9b9b668e913f02ebd35804ef7/type 
application/octet-stream

Then you can do things such as If-Modified-Since and helps when looking at implementing a simple proxy.

When caching more things than OS images, it is also useful to record the content type (deb, tar, whatever)

WARN[0000] reference for unknown type: application/octet-stream


The information is available in the Result, when retreiving cached files (but the string can be empty)

It would be possible to add the content instead, and use empty string for older cache without the files.

 type Result struct {
        Status          Status
        CachePath       string // "/Users/foo/Library/Caches/lima/download/by-url-sha256/<SHA256_OF_URL>/data"
+       LastModified    time.Time
+       ContentType     string
        ValidatedDigest bool
 }

@afbjorklund afbjorklund marked this pull request as draft May 27, 2024 14:31
@afbjorklund afbjorklund force-pushed the cache-time branch 2 times, most recently from 3fc2e78 to a582fc1 Compare May 27, 2024 15:33
@afbjorklund afbjorklund marked this pull request as ready for review May 27, 2024 18:17
@afbjorklund
Copy link
Member Author

Now the user (proxy) will need to use time.IsZero and time.Format(time.RFC1123), for LastModified

@afbjorklund afbjorklund force-pushed the cache-time branch 2 times, most recently from ceb657a to 31916a2 Compare June 2, 2024 12:09
@afbjorklund
Copy link
Member Author

Added some unit tests.

@AkihiroSuda AkihiroSuda added this to the v1.0 (tentative) milestone Jul 17, 2024
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit 1d1ce3c into lima-vm:master Jul 17, 2024
27 checks passed
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

Successfully merging this pull request may close these issues.

2 participants