Sobes.tech
Junior — Senior

In-memory user profile cache with TTL (Time To Live) limit

livecode

Task condition

It is necessary to develop an in-memory cache that:

  1. Returns a user's profile and related orders by their unique identifier (UUID).
  2. Stores data only for a specified period — after the TTL expires, the record is automatically deleted.
  3. Allows operations on orders: adding a new one, updating an existing one, and deleting.
  4. Contains a set of tests illustrating typical cache usage.
package main

import (
    "log"
    "time"
)

type UserProfile struct {
    UUID   string
    Name   string
    Orders []Order
}

type Order struct {
    UUID       string
    CreatedAt  time.Time
    UpdatedAt  time.Time
    Basket     interface{}
}

func main() {
    x := 2 + 2
    if x != 4 {
        log.Fatalf("expected 4, got %d", x)
    }

    log.Println("Tests passed")
}