Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • To avoid confusion for the user of the method, the attribute should not be applied on a method that accepts parameters, since the method will always return the same results even when called with different parameter values.
  • This attribute is intended for expensive calculations, it is not recommended for short methods and properties.
  • The modified method will be made thread safe through the use of a lock.

Example.

Code Block
"""/*
doing expensive processing
1234
1234
"""*/

import Useful.Attributes
from
"Boo.Lang.Useful"

class OnceTest:

    [Once]
    def expensiveFunction():
        # Do expensive processing here
        print "doing expensive processing"
        resultOfExpensiveProcessing = 1234

        # ... and return results
        return resultOfExpensiveProcessing

onceTest = OnceTest()
print onceTest.expensiveFunction()
print onceTest.expensiveFunction()

...