《高阶Perl》——3.8 对象方法里的缓存

    xiaoxiao2022-06-09  194

    3.8 对象方法里的缓存

    对象方法,它经常不理解地把缓存的值保存在独立的散列里。考虑一个投资银行写的程序里的Investor对象。该对象表现了银行的一个客户:

    package Investor; # Compute total amount currently invested sub total { my $self = shift; # ... complex computation performed here ... return $total; }

    如果$total不会改变,就可以缓存它,用对象的本身作为缓存散列的键:

    # Compute total amount currently invested { my
    转载请注明原文地址: https://yun.8miu.com/read-14677.html

    最新回复(0)