htmgo/framework/h
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
..
cache Refactor caching system to use pluggable stores (#98) 2025-07-03 14:07:16 -05:00
app.go add info on how to change it 2025-01-06 10:26:15 -06:00
array.go cleanup usage of orderedmap 2024-10-29 05:48:13 -05:00
array_test.go cleanup usage of orderedmap 2024-10-29 05:48:13 -05:00
attribute.go Websocket Extension - Alpha (#22) 2024-11-09 12:05:53 -06:00
attribute_test.go more tests 2024-10-31 11:36:57 -05:00
base.go css form on blur validation 2024-10-31 09:44:16 -05:00
base_test.go swap tests 2024-10-31 11:59:19 -05:00
cache.go Refactor caching system to use pluggable stores (#98) 2025-07-03 14:07:16 -05:00
cache_integration_test.go Refactor caching system to use pluggable stores (#98) 2025-07-03 14:07:16 -05:00
command_test.go add RunAfterTimeout & RunOnInterval 2024-11-16 08:45:03 -06:00
conditionals.go add some comments 2024-10-25 21:59:17 -05:00
conditionals_test.go conditional tests 2024-10-31 11:11:09 -05:00
env.go add ent for sql 2024-09-17 10:41:29 -05:00
extensions.go Revert "websocket stuff wip" 2024-10-09 10:30:14 -05:00
extensions_test.go ordered map tests, extensions test 2024-10-31 11:43:24 -05:00
header.go Revert "websocket stuff wip" 2024-10-09 10:30:14 -05:00
header_test.go more tests 2024-10-31 11:36:57 -05:00
lifecycle.go add RunAfterTimeout & RunOnInterval 2024-11-16 08:45:03 -06:00
livereload.go swap out echo with std lib 2024-09-26 14:41:46 -05:00
qs.go Merge remote-tracking branch 'origin/master' 2024-10-25 22:01:04 -05:00
qs_test.go more tests 2024-10-31 11:36:57 -05:00
render.go Merge remote-tracking branch 'origin/master' 2024-10-25 22:01:04 -05:00
render_test.go Refactor caching system to use pluggable stores (#98) 2025-07-03 14:07:16 -05:00
renderables.go update attrs to use ordered map 2024-09-30 12:39:48 -05:00
renderer.go JS Eval Enhancements (#62) 2024-10-29 08:44:52 -05:00
serialize.go more tests 2024-10-31 11:36:57 -05:00
serialize_test.go more tests 2024-10-31 11:36:57 -05:00
swap.go add htmx to window 2024-10-07 12:57:24 -05:00
swap_test.go more tests 2024-10-31 11:36:57 -05:00
tag.go Websocket Extension - Alpha (#22) 2024-11-09 12:05:53 -06:00
tag_test.go more tests 2024-10-31 11:36:57 -05:00
xhr.go Merge remote-tracking branch 'origin/master' 2024-10-25 22:01:04 -05:00
xhr_test.go swap tests 2024-10-31 11:59:19 -05:00