8 // Calls os.Stat() on the file or folder that backs the given key.
9 func (cd *CacheDir) Stat(key ...CacheKey) (stat os.FileInfo, err error) {
10 lock, err := cd.Lock(key...)
16 fh, err := cd.Open(key...)
25 // Updates the mtime of the file backing the given key.
27 // Creates an empty file if it doesn't exist.
28 func (cd *CacheDir) Touch(key ...CacheKey) (err error) {
29 lock, err := cd.Lock(key...)
34 case os.IsNotExist(err):
40 if err = cd.ChtimeNoLock(time.Now(), key...); err == nil {
44 fh, err := cd.OpenFlags(os.O_APPEND|os.O_CREATE, key...)
48 case os.IsNotExist(err): // directory path not created yet
49 fh, err = cd.Create(key...)
59 // Same as Chtime, but does not try to acquire a file lock on the file
60 // before. Only call this if you already hold a lock to the file.
61 func (cd *CacheDir) ChtimeNoLock(t time.Time, key ...CacheKey) (err error) {
62 return os.Chtimes(cd.cachePath(key...), time.Now(), t)
65 // Sets the mtime of the file backing the given key to the specified time.
66 func (cd *CacheDir) Chtime(t time.Time, key ...CacheKey) (err error) {
67 lock, err := cd.Lock(key...)
73 return cd.ChtimeNoLock(t, key...)