Commit graph

10 commits

Author SHA1 Message Date
franchb
cfcfe7cb21
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
2025-07-03 17:46:09 +03:00
Eliah Rusin
04997d7315
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>
2025-06-26 21:38:38 +03:00
maddalax
3468baaa84 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	framework/h/attribute.go
#	framework/h/lifecycle.go
#	framework/h/render.go
2024-10-25 22:01:04 -05:00
maddalax
cf76ca4f98 add some comments 2024-10-25 21:59:17 -05:00
Mohammad javad
a0f5b5dfd5
feat:add claasf (#31)
* feat:add claasf

* refactor(tag.go)

* refactor(cache.go)

* refactor(attribute.go)

* refactor(app.go)

* refactor(attribute.go)
2024-10-22 08:32:17 -05:00
maddalax
513c0fb432 add more sleep time for the cache cleaner 2024-09-28 12:40:48 -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