htmgo/htmgo-site
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/public new favicon 2024-10-30 14:07:38 -05:00
internal log http requests 2024-11-12 18:15:59 -06:00
md New Docs (#63) 2024-10-30 13:27:42 -05:00
pages Refactor caching system to use pluggable stores (#98) 2025-07-03 14:07:16 -05:00
partials add discord link 2024-10-31 13:55:27 -05:00
ui mobile fixes css 2024-11-25 10:34:22 -06:00
.dockerignore fix docker 2024-09-24 12:46:17 -05:00
assets.go dont embed assets in dev to speed up live reload 2024-09-25 10:44:43 -05:00
assets_prod.go dont embed assets in dev to speed up live reload 2024-09-25 10:44:43 -05:00
Dockerfile dont download a version 2024-09-26 15:38:34 -05:00
go.mod Auto-update HTMGO framework version 2025-01-06 16:27:11 +00:00
go.sum Auto-update HTMGO framework version 2025-01-06 16:27:11 +00:00
htmgo.yml cleanup 2024-10-30 13:29:20 -05:00
main.go add info on how to change it 2025-01-06 10:26:15 -06:00
package-lock.json dont replace tailwind file 2024-09-23 12:27:04 -05:00
package.json dont replace tailwind file 2024-09-23 12:27:04 -05:00
tailwind.config.js add some more docs 2024-09-24 12:39:16 -05:00
Taskfile.yml fix taskfile 2024-10-10 09:30:37 -05:00