htmgo - build simple and scalable systems with go + htmx
Find a file
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
.github astgen only 2024-11-11 10:12:29 -06:00
cli/htmgo make run server build the binary instead of outputting each run to a tmp file 2025-01-24 11:51:01 -06:00
examples Auto-update HTMGO framework version 2025-01-06 16:27:11 +00:00
extensions/websocket Auto-update HTMGO framework version 2025-01-06 16:27:11 +00:00
framework Refactor caching system to use pluggable stores (#98) 2025-07-03 14:07:16 -05:00
framework-ui Auto-update HTMGO framework version 2025-01-06 16:27:11 +00:00
htmgo-site Refactor caching system to use pluggable stores (#98) 2025-07-03 14:07:16 -05:00
templates/starter Auto-update HTMGO framework version 2025-01-06 16:27:11 +00:00
tools fix:parser_test remove impossible condition (#44) 2024-10-25 12:41:32 -05:00
.gitignore Revert "check in go.work" 2024-10-24 08:41:36 -05:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2024-10-11 23:33:23 -05:00
LICENSE Create LICENSE 2024-09-25 09:56:24 -05:00
README.md remove new lines 2024-11-28 10:13:23 -06:00
tailwind-lsp-config.json add tailwind intellisense notes 2024-10-13 06:35:27 -05:00

htmgo

build simple and scalable systems with go + htmx


Go Report Card Build Go Reference codecov Join Discord GitHub Sponsors

looking for a python version? check out: https://fastht.ml

introduction:

htmgo is a lightweight pure go way to build interactive websites / web applications using go & htmx.

By combining the speed & simplicity of go + hypermedia attributes (htmx) to add interactivity to websites, all conveniently wrapped in pure go, you can build simple, fast, interactive websites without touching javascript. All compiled to a single deployable binary.

func IndexPage(ctx *h.RequestContext) *h.Page {
  now := time.Now()
  return h.NewPage(
    h.Div(
      h.Class("flex gap-2"),
      h.TextF("the current time is %s", now.String())
    )
  )
}

core features:

  1. deployable single binary
  2. live reload (rebuilds css, go, ent schema, and routes upon change)
  3. automatic page and partial registration based on file path
  4. built in tailwindcss support, no need to configure anything by default
  5. custom htmx extensions to reduce boilerplate with common tasks

get started:

View documentation on htmgo.dev.

Star History

Star History Chart