Commit graph

21 commits

Author SHA1 Message Date
Eliah Rusin
06f01b3d7c
Refactor caching system to use pluggable stores (#98)
* Refactor caching system to use pluggable stores

The commit modernizes the caching implementation by introducing a pluggable store interface that allows different cache backends. Key changes:

- Add Store interface for custom cache implementations
- Create default TTL-based store for backwards compatibility
- Add example LRU store for memory-bounded caching
- Support cache store configuration via options pattern
- Make cache cleanup logic implementation-specific
- Add comprehensive tests and documentation

The main goals were to:

1. Prevent unbounded memory growth through pluggable stores
2. Enable distributed caching support
3. Maintain backwards compatibility
4. Improve testability and maintainability

Signed-off-by: franchb <hello@franchb.com>

* Add custom cache stores docs and navigation

Signed-off-by: franchb <hello@franchb.com>

* Use GetOrCompute for atomic cache access

The commit introduces an atomic GetOrCompute method to the cache interface and refactors all cache implementations to use it. This prevents race conditions and duplicate computations when multiple goroutines request the same uncached key simultaneously.

The changes eliminate a time-of-check to time-of-use race condition in the original caching implementation, where separate Get/Set operations could lead to duplicate renders under high concurrency.

With GetOrCompute, the entire check-compute-store operation happens atomically while holding the lock, ensuring only one goroutine computes a value for any given key.

The API change is backwards compatible as the framework handles the GetOrCompute logic internally. Existing applications will automatically benefit from the

* rename to WithCacheStore

---------

Signed-off-by: franchb <hello@franchb.com>
Co-authored-by: maddalax <jm@madev.me>
2025-07-03 14:07:16 -05:00
maddalax
ef83e34b1e add RunAfterTimeout & RunOnInterval 2024-11-16 08:45:03 -06:00
maddalax
bb9fb0b327 write doctype when rendering html 2024-10-23 09:28:19 -05:00
maddalax
e6af7a73d5 fix test 2024-10-03 15:41:09 -05:00
maddalax
496981efd0 fix tests 2024-10-03 15:35:19 -05:00
maddalax
e5c5014812 more tests 2024-09-30 13:01:51 -05:00
maddalax
3c4583c2b3 cleanup 2024-09-30 12:47:10 -05:00
maddalax
7b83e2fde7 update attrs to use ordered map 2024-09-30 12:39:48 -05:00
maddalax
2d333a6e0a escape Text input, rename Raw to UnsafeRaw 2024-09-28 20:45:27 -05:00
maddalax
af81f53160 fix expiration for non by key cache
add goroutine to clean up old cache entries to save mem
2024-09-28 12:38:42 -05:00
maddalax
61e5554f20 make sure the expiration is per key too 2024-09-28 11:56:29 -05:00
maddalax
17bb55655e add caching per key 2024-09-28 11:27:07 -05:00
maddalax
010ab1fdd6 add caching component support 2024-09-27 21:29:53 -05:00
maddalax
1ac2d630c7 dont close void tags 2024-09-27 16:18:09 -05:00
maddalax
1208857c5f static / dynamic test 2024-09-27 10:20:50 -05:00
maddalax
8b34b63990 some optimizations 2024-09-27 10:10:00 -05:00
maddalax
cf5171c237 add benchmarks 2024-09-27 09:46:45 -05:00
maddalax
e77ab0bc28 fix framework tests (sort attributes) 2024-09-26 16:01:41 -05:00
maddalax
a58cb051e8 some cleanup, alias funcs in js package to know which commands can be used with lifecycle 2024-09-22 20:59:44 -05:00
maddalax
8562f9e85e remove ternary 2024-09-22 11:25:18 -05:00
maddalax
279a3c7163 add a few tests 2024-09-19 21:13:08 -05:00