|
Download task_014/instruction.md from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_014/instruction.md
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_014/instruction.md
-
curl -L -o instruction.md https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_014/instruction.md
1.48 kB
| # Renewing reads for a Go LRU cache | |
| Extend the supplied Go cache without changing ordinary `Get` expiration behavior. Add a separate read method that renews a live entry's original time to live. Keep existing cache APIs and capacity-based LRU eviction. | |
| ## API and expiry | |
| - Keep `NewCache(capacity int) *Cache` and provide `NewCacheWithClock(capacity int, now func() time.Time) *Cache`. Setting, reading and checking expiry use the injected clock. | |
| - `GetAndRenewTTL(key string) (string, bool)` returns a live value and sets its expiry to the current time plus the duration from the most recent write. Repeated renewals use that original duration, not the remaining time or the previous deadline. A renewal counts as access for LRU recency. | |
| - A missing entry or one with `now >= expiresAt` returns a miss and cannot be revived. Plain `Get` never extends a TTL. A non-expiring entry can be read with either method without gaining a deadline. Replacing an entry with a new TTL updates the duration used for later renewals. | |
| Write unit tests for renewal and run `go test ./...` offline. | |
| ## Acceptance Checklist | |
| - Normal reads and eviction still work. Renewing a live entry returns its value and makes it recently used. | |
| - A renewal extends expiry by the full most recently set TTL. Overwriting and repeated renewal use the correct duration. | |
| - Plain reads do not renew. An entry misses at or after its deadline and stays expired; entries written without TTL remain non-expiring. | |