memoizerGuard.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.lang.aspect.memoizerGuard"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.lang.aspect.memoizerGuard"] = true;
  8. dojo.provide("dojox.lang.aspect.memoizerGuard");
  9. (function(){
  10. var aop = dojox.lang.aspect,
  11. reset = function(/*String|Array?*/ method){
  12. var that = aop.getContext().instance, t;
  13. if(!(t = that.__memoizerCache)){ return; }
  14. if(arguments.length == 0){
  15. delete that.__memoizerCache;
  16. }else if(dojo.isArray(method)){
  17. dojo.forEach(method, function(m){ delete t[m]; });
  18. }else{
  19. delete t[method];
  20. }
  21. };
  22. aop.memoizerGuard = function(/*String|Array?*/ method){
  23. // summary:
  24. // Invalidates the memoizer's cache (see dojox.lang.aspect.memoizer)
  25. // after calling certain methods.
  26. //
  27. // method:
  28. // Optional method's name to be guarded: only cache for
  29. // this method will be invalidated on call. Can be a string
  30. // or an array of method names. If omitted the whole cache
  31. // will be invalidated.
  32. return { // Object
  33. after: function(){ reset(method); }
  34. };
  35. };
  36. })();
  37. }