caching icon indicating copy to clipboard operation
caching copied to clipboard

Deadlock while loading another cache in fallback of load()

Open Vlczech opened this issue 7 years ago • 4 comments

  • bug report? yes
  • feature request? no
  • version: 2.5.6 (nette/caching)

Description

When trying to load cache by fallback in another fallback of load, script runs to infinity (maybe deadlock?)

Steps To Reproduce

public function runMethodWithCache() {
$cachedValue1 = $this->cache->load('cached_value_1', function(& $dependencies) {
        $dependencies['expire'] = '+1 day';
        $value = $this->runAnotherMethodWithCache();        
        return $value;
      });
}

private function runAnotherMethodWithCache() {
      $usedValue = 'something';
      $this->someValue = $this->cache->load('cached_value_2', function (& $dependencies) use ($usedValue) {
        $dependencies[Cache::ITEMS] = ['cached_value_1'];
        return $usedValue;
      });

     return 'something another';
}

When I comment following lines from second method, script running as expected.

      $this->someValue = $this->cache->load('cached_value_2', function (& $dependencies) use ($usedValue) {
        $dependencies[Cache::ITEMS] = ['cached_value_1'];
        return $usedValue;
      });

[UPDATE 1]: most probably, this is caused by cross dependency of Cache::ITEMS in second method, which is dependent on first one cache.

Idea

If subloading of cache is not possible, it should be inspect to avoid sub-loading of cache.

Vlczech avatar Feb 04 '18 14:02 Vlczech

This is imho expected behavior, dependencies must form directed acyclic graph.

JanTvrdik avatar Feb 04 '18 18:02 JanTvrdik

Can you fix it and send a PR?

dg avatar Feb 06 '18 16:02 dg

@dg I can try to fix it, but it will not be soon.

Vlczech avatar Mar 02 '18 13:03 Vlczech

It is ok

dg avatar Mar 02 '18 15:03 dg