lima icon indicating copy to clipboard operation
lima copied to clipboard

Store time of last modified in cache dir

Open afbjorklund opened this issue 1 year ago • 1 comments

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.

  • #2367

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 avatar May 27 '24 11:05 afbjorklund

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

afbjorklund avatar Jun 02 '24 12:06 afbjorklund

Added some unit tests.

afbjorklund avatar Jul 17 '24 08:07 afbjorklund