Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

25
LINES

< > BotCompany Repo | #1011310 // DependentCache

JavaX fragment (include)

1  
// f is a function or an instance of Cache (the dependee)
2  
sclass DependentCache<A> extends Cache<A> {
3  
  O depF, lastDep;
4  
  
5  
  *() {}
6  
  *(O *maker, O *depF) {}
7  
  
8  
  A get() {
9  
    if (hasLock(lock)) ret value; // Must be called from within maker
10  
    {
11  
      lock lock;
12  
      O dep;
13  
      if (depF instanceof Cache) dep = depF/Cache.changeCount;
14  
      else {
15  
        dep = callF(depF);
16  
        if (dep instanceof Cache) dep = dep/Cache.changeCount;
17  
      }
18  
      if (neq(dep, lastDep)) {
19  
        clear();
20  
        lastDep = dep;
21  
      }
22  
    }
23  
    ret super.get();
24  
  }
25  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1011310
Snippet name: DependentCache
Eternal ID of this version: #1011310/6
Text MD5: d505bfb8dcf5b87142e3bb1b2a877729
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-22 12:04:33
Source code size: 589 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 501 / 2055
Version history: 5 change(s)
Referenced in: [show references]