"""PraxisAI synthetic debugging exercise. Intentionally contains bugs.

Contract: each cache is independent. set(key, value, ttl=60) stores any value
for a nonnegative, finite number of seconds. At now >= insertion time + ttl,
the entry is expired. ttl=0 expires immediately. get returns the stored value
before expiry (including 0, False, "", or None); otherwise it returns default.
The supplied clock is nondecreasing. No background cleanup is required.
"""


class TTLCache:
    def __init__(self, clock):
        self.clock = clock
        self.entries = {}

    def set(self, key, value, ttl=60):
        self.entries[key] = (value, self.clock() + (ttl or 60))

    def get(self, key, default=None):
        entry = self.entries.get(key)
        if entry is None:
            return default
        value, expires_at = entry
        if self.clock() > expires_at:
            del self.entries[key]
            return default
        return value or default
