Back to tasks
КуперGet help with live coding in real time with Sobes Copilot
Junior — Senior
27
In‑memory cache for user profiles and their orders
Companies where asked:
Task condition
Implement an in‑memory cache that, given a key, returns a user profile together with the list of its orders.
Requirements:
- The cache must support a TTL (time‑to‑live) for stored entries.
- The cache should be usable from any function that processes orders.
- Provide test scenarios that demonstrate the cache’s behavior.
package main
import (
"log"
"time"
)
type UserProfile struct {
UUID string
Name string
Orders []Order
}
type Order struct {
UUID string
CreateAt time.Time
UpdateAt time.Time
Basket interface{}
}
func main() {
result := 2 + 2
if result != 4 {
log.Fatalf("expected 4, got %d", result)
}
log.Println("Tests passed")
}