https://github.com/darky/glemo
Simple function memoization over Erlang ETS / JavaScript Map for Gleam
https://github.com/darky/glemo
gleam memoize
Last synced: 3 months ago
JSON representation
Simple function memoization over Erlang ETS / JavaScript Map for Gleam
- Host: GitHub
- URL: https://github.com/darky/glemo
- Owner: darky
- Created: 2024-05-17T16:08:46.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-19T16:26:25.000Z (over 1 year ago)
- Last Synced: 2025-12-01T13:45:03.491Z (6 months ago)
- Topics: gleam, memoize
- Language: Gleam
- Homepage:
- Size: 17.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# glemo
[](https://hex.pm/packages/glemo)
[](https://hexdocs.pm/glemo/)


Simple function memoization over Erlang ETS / JavaScript Map for Gleam
```sh
gleam add glemo
```
```gleam
import glemo
pub fn main() {
// init caches on application startup
glemo.init(["my_cache"])
// try get from cache
// on first attempt item not exists in cache
// fallback function will be called
// result of fallback function will be placed to cache, function argument is used as key
1
|> glemo.memo("my_cache", fn(x) { x + 1 }) // 2
// now value returned from cache, fallback function ignored
1
|> glemo.memo("my_cache", fn(x) { x + 1 }) // 2
// invalidate cache item by specific key
glemo.invalidate_specific(1, "my_cache")
// invalidate all cache
glemo.invalidate_all("my_cache")
}
```
Further documentation can be found at .
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
gleam shell # Run an Erlang shell
```