htmgo/framework
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
..
assets fix loading livereload extension 2024-11-09 12:32:30 -06:00
config gen code for assets (#68) 2024-11-01 06:10:35 -05:00
datastructure/orderedmap ordered map tests, extensions test 2024-10-31 11:43:24 -05:00
h Refactor caching system to use pluggable stores (#98) 2025-07-03 14:07:16 -05:00
hx update onload to always be called when element gets rendered again 2024-10-11 08:56:56 -05:00
internal cleanup usage of orderedmap 2024-10-29 05:48:13 -05:00
js add RunAfterTimeout & RunOnInterval 2024-11-16 08:45:03 -06:00
service comments about the service locator 2024-10-25 22:06:58 -05:00
framework.go test 2024-09-24 15:59:24 -05:00
go.mod Auto-update HTMGO framework version 2024-10-14 15:17:42 +00:00
go.sum fix framework tests (sort attributes) 2024-09-26 16:01:41 -05:00
LICENSE framework license 2024-09-26 16:12:21 -05:00