@@ -33,8 +33,9 @@ local Cache = {}
3333Cache .__index = Cache
3434
3535
36- --- @param config ? CacheConfig
37- --- @return Cache
36+ --- Creates a new Cache instance with optional configuration.
37+ --- @param config ? CacheConfig Cache configuration (MaxSize , DefaultTTL )
38+ --- @return Cache cache New cache instance
3839function Cache .new (config )
3940 local CL = log .inSection (" Cache" )
4041
@@ -50,8 +51,9 @@ function Cache.new(config)
5051end
5152
5253
53- --- @param key string
54- --- @return string ? response
54+ --- Retrieves a cached response by key. Returns nil if expired or not found.
55+ --- @param key string Cache key (typically " METHOD:path" )
56+ --- @return string ? response Cached HTTP response or nil
5557function Cache :get (key )
5658 local entry = self ._entries [key ]
5759 if not entry then return nil end
@@ -66,9 +68,10 @@ function Cache:get(key)
6668end
6769
6870
69- --- @param key string
70- --- @param response string
71- --- @param ttl ? number TTL em segundos (usa default se nil )
71+ --- Stores a response in the cache. Evicts oldest entry if cache is full.
72+ --- @param key string Cache key (typically " METHOD:path" )
73+ --- @param response string HTTP response string to cache
74+ --- @param ttl ? number TTL in seconds (uses DefaultTTL if nil )
7275function Cache :set (key , response , ttl )
7376 if not self ._entries [key ] then
7477 -- Evict oldest if full
@@ -85,7 +88,8 @@ function Cache:set(key, response, ttl)
8588end
8689
8790
88- --- @param key string
91+ --- Removes a single entry from the cache.
92+ --- @param key string Cache key to invalidate
8993function Cache :invalidate (key )
9094 if self ._entries [key ] then
9195 self ._entries [key ] = nil
@@ -94,6 +98,7 @@ function Cache:invalidate(key)
9498end
9599
96100
101+ --- Removes all entries from the cache.
97102function Cache :clear ()
98103 self ._entries = {}
99104 self ._size = 0
@@ -118,9 +123,11 @@ function Cache:_evict()
118123end
119124
120125
121- --- @param cacheInstance Cache
122- --- @param ttl ? number TTL customizado
123- --- @return PipelineEntry
126+ --- Creates a PipelineEntry that caches GET responses.
127+ --- Only caches GET requests. Cache key format: "method:path".
128+ --- @param cacheInstance Cache The cache instance to use
129+ --- @param ttl ? number Custom TTL in seconds (uses cache ' s DefaultTTL if nil)
130+ --- @return PipelineEntry entry Pipeline handler ready for Server : UseHandler ()
124131function Cache .createPipelineHandler (cacheInstance , ttl )
125132 return {
126133 name = " cache" ,
0 commit comments