| |
| Recipe 2.11: Creating 'Memoized' Attributes and Methods |
Last Updated: Sep 8, 2003
Status: Draft
|
|
|
|
How important is this problem to you?
(Login to Vote)
4.67 Rating, 3 Votes
|
|
How acceptable is the proposed solution?
(Login to Vote)
4.00 Rating, 2 Votes
|
|
Problem:
   
You want to create an attribute or method that will be initialized (possibly using a very complex, time-consuming algorithm) the first time it is used, but thereafter uses the initialized, cached value.
Solution:
  
Use the is once property:
method foo is once { ... }
Discussion:
Issue:
Other possible keyword choices include is cached or is memoized.
|
|