Sobes.tech
Back to tasks
Junior — Senior
27

In‑memory cache for user profiles and their orders

Companies where asked:

КуперКупер
Get help with live coding in real time with Sobes Copilot
Task condition

Implement an in‑memory cache that, given a key, returns a user profile together with the list of its orders.

Requirements:

  1. The cache must support a TTL (time‑to‑live) for stored entries.
  2. The cache should be usable from any function that processes orders.
  3. 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")
}