Install oyzem
using go get
:
go get -u github.com/simplyYan/oyzem
oyzem is a lightweight and easy-to-use Go library for memoization, providing a simple mechanism to cache function results and improve performance. Features
- Easy: Simple API for memoizing functions.
- Fast: Efficient caching using a mutex for thread safety.
- Lightweight: Minimalistic design with a focus on simplicity.
- Objective: Aims to provide a clear and straightforward memoization solution.
oyzem is distributed under the BSD-3-Clause License. See the LICENSE file for details.
package main
import (
"fmt"
"github.com/simplyYan/oyzem"
)
func main() {
// Create a new Memoizer instance
memoizer := oyzem.New()
// Memoize a function
memoizedFn, _ := memoizer.Memoize(func(a, b int) int {
fmt.Println("Performing calculation...")
return a + b
})
// Run the memoized function
result, _ := memoizer.Run(memoizedFn, 2, 3)
fmt.Println("Result:", result)
}
package main
import (
"fmt"
"github.com/simplyYan/oyzem"
)
func main() {
// Create a new Memoizer instance
memoizer := oyzem.New()
// Memoize a function
memoizedFn, _ := memoizer.Memoize(func(a, b int) int {
fmt.Println("Performing calculation...")
return a + b
})
// Run the memoized function
result1, _ := memoizer.Run(memoizedFn, 2, 3)
fmt.Println("Result 1:", result1)
// Run the memoized function again (result obtained from the cache)
result2, _ := memoizer.Run(memoizedFn, 2, 3)
fmt.Println("Result 2 (from cache):", result2)
// Run the memoized function with different arguments
result3, _ := memoizer.Run(memoizedFn, 4, 5)
fmt.Println("Result 3:", result3)
}
Contributions to oyzem are welcome! If you want to add, fix, or improve features, follow these steps:
- Fork the repository on GitHub.
- Clone your forked repository: git clone https://github.com/your-username/oyzem.git.
- Create a new branch: git checkout -b feature-name.
- Make your changes and commit: git commit -m "Description of changes".
- Push your branch to GitHub: git push origin feature-name.
- Open a pull request on the official oyzem repository.