diff options
Diffstat (limited to 'doc/development/utilities.md')
-rw-r--r-- | doc/development/utilities.md | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/doc/development/utilities.md b/doc/development/utilities.md index 551834670b3..58954101890 100644 --- a/doc/development/utilities.md +++ b/doc/development/utilities.md @@ -181,20 +181,6 @@ Refer to [`strong_memoize.rb`](https://gitlab.com/gitlab-org/gitlab/-/blob/maste include Gitlab::Utils::StrongMemoize def result - strong_memoize(:result) do - search - end - end - end - ``` - - Alternatively, use the `strong_memoize_attr` helper to memoize the method for you: - - ```ruby - class Find - include Gitlab::Utils::StrongMemoize - - def result search end strong_memoize_attr :result @@ -206,6 +192,26 @@ Refer to [`strong_memoize.rb`](https://gitlab.com/gitlab-org/gitlab/-/blob/maste end ``` + Using `strong_memoize_attr` on methods with parameters is not supported. + It does not work when combined with [`override`](#override) and might memoize wrong results. + + Use `strong_memoize_with` instead. + + ```ruby + # bad + def expensive_method(arg) + # ... + end + strong_memoize_attr :expensive_method + + # good + def expensive_method(arg) + strong_memoize_with(:expensive_method, arg) + # ... + end + end + ``` + There's also `strong_memoize_with` to help memoize methods that take arguments. This should be used for methods that have a low number of possible values as arguments or with consistent repeating arguments in a loop. |