<?xml version="1.0" encoding="UTF-8"?>
<!--
  Ehcache 3 configuration (JCache / JSR-107 format).
  Referenced by: spring.cache.jcache.config=classpath:ehcache3.xml

  Two caches:
    "user"     — single User entities keyed by ID (e.g. @Cacheable(value="user", key="#id"))
    "userList" — full user list (e.g. @Cacheable(value="userList"))

  TTI (time-to-idle) evicts entries not accessed within the specified window,
  preventing stale data accumulation and cache stampede from eternal entries.
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.ehcache.org/v3"
        xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd">

    <!-- Single user entity cache: up to 5 000 entries, evict if idle for 5 minutes -->
    <cache alias="user">
        <expiry>
            <tti unit="minutes">5</tti>
        </expiry>
        <heap unit="entries">5000</heap>
    </cache>

    <!-- Full user-list cache: small number of keys, evict after 2 minutes (reduces stampede risk) -->
    <cache alias="userList">
        <expiry>
            <ttl unit="minutes">2</ttl>
        </expiry>
        <heap unit="entries">10</heap>
    </cache>

</config>
