module Lucky::Memoizable

Direct including types

Defined in:

lucky/memoizable.cr

Macro Summary

Macro Detail

macro memoize(method_def) #

Caches the return value of the method. Helpful for expensive methods that are called more than once.

To memoize a method, prefix it with memoize:

class BrowserAction
  memoize def current_user : User
    # Get the current user
  end
end

This will fetch the user record on the first current_user call, then each subsequent call returns the user record.

The memoize method will raise a compile time exception if you forget to include a return type for your method, or if your return type is a Union. Arguments are not allowed in memoized methods because these can change the return value.


[View source]