Get retrieves a cached file path if it exists sha parameter should be the resolved commit SHA
(owner, repo, path, sha string)
| 70 | // Get retrieves a cached file path if it exists |
| 71 | // sha parameter should be the resolved commit SHA |
| 72 | func (c *ImportCache) Get(owner, repo, path, sha string) (string, bool) { |
| 73 | // Use SHA-based approach: cache files are stored by commit SHA |
| 74 | // Cache path: .github/aw/imports/owner/repo/sha/sanitized_path.md |
| 75 | sanitizedPath := sanitizePath(path) |
| 76 | relativeCachePath := filepath.Join(ImportCacheDir, owner, repo, sha, sanitizedPath) |
| 77 | fullCachePath := filepath.Join(c.baseDir, relativeCachePath) |
| 78 | |
| 79 | // Check if the cached file exists |
| 80 | if _, err := os.Stat(fullCachePath); err != nil { |
| 81 | if os.IsNotExist(err) { |
| 82 | importCacheLog.Printf("Cache miss: %s/%s/%s@%s", owner, repo, path, sha) |
| 83 | } else { |
| 84 | // Log other types of errors (permissions, I/O issues, etc.) |
| 85 | importCacheLog.Printf("Cache access error for %s/%s/%s@%s: %v", owner, repo, path, sha, err) |
| 86 | } |
| 87 | return "", false |
| 88 | } |
| 89 | |
| 90 | importCacheLog.Printf("Cache hit: %s/%s/%s@%s -> %s", owner, repo, path, sha, fullCachePath) |
| 91 | return fullCachePath, true |
| 92 | } |
| 93 | |
| 94 | // Set stores a new cache entry by saving the content to the cache directory |
| 95 | // sha parameter should be the resolved commit SHA |