Created
December 28, 2017 20:10
-
-
Save jonbodner/78e0f454d37f1db69a24e1df414b21a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Takes in a function and a time.Duration and returns a caching version of the function | |
// | |
// The limitations on memoization are: | |
// | |
// — there must be at least one in parameter | |
// | |
// — there must be at least one out parameter | |
// | |
// — the in parameters must be comparable. That means they cannot be of kind slice, map, or func, | |
// nor can input parameters be structs that contain (at any level) slices, maps, or funcs. | |
// | |
// Be aware that if your memoized function has any side-effects (does anything that isn’t | |
// reflected in the output, like print to the screen or write to a database) the side-effects | |
// will be performed by the function only the first time that the function is invoked with | |
// particular set of values. | |
func Cacher(f interface{}, expiration time.Duration) (interface{}, error) { | |
return f, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment