Similar to "getter", but for values that are to be lazily generated and cached.
This is useful for values that are complex to generate, not always used, and
either never or infrequently change.
The first time the getter is called, the generator function you have provided
is run, and it's return value is cached and returned. On subsequent calls to
the getter, the cached value is returned without the generator function being
called. The cache can be cleared, thus forcing the value to be re-generated
upon the next getter call, by setting "_myVarName_cached" to false.
Example use-case: If you have a property created by getter() and want
to change the "get" from a trivial "return _blah" to a more involved function,
you will most likely just simply switch from getter to getterLazy.
Additional Info:
If you don't want the value to ever be cached, just set "_myVarName_cached"
to false within your provided generator function.
Usage:
mixin(getterLazy!(int, "myVar", `
// Ordinarily, this function would be more complex
return 7;
`));
mixin(getterLazy!("protected", int, "myVar2", `return 7;`));
mixin(getterLazy!(string, "str"));
privatestring_str_gen()
{
return"Hello";
}
Similar to "getter", but for values that are to be lazily generated and cached. This is useful for values that are complex to generate, not always used, and either never or infrequently change.
The first time the getter is called, the generator function you have provided is run, and it's return value is cached and returned. On subsequent calls to the getter, the cached value is returned without the generator function being called. The cache can be cleared, thus forcing the value to be re-generated upon the next getter call, by setting "_myVarName_cached" to false.
Example use-case: If you have a property created by getter() and want to change the "get" from a trivial "return _blah" to a more involved function, you will most likely just simply switch from getter to getterLazy.
Additional Info:
If you don't want the value to ever be cached, just set "_myVarName_cached" to false within your provided generator function.
Usage:
Turns Into: