src/Rbac/DbManager.php
public function loadFromCache()
    {
        if ($this->items !== null || !$this->cache instanceof ExtendedCacheInterface) {
            return resolve(true);
        }

        return $this->cache->get($this->cacheKey, [])
            ->then(function($data) {
                if (is_array($data) && isset($data[0], $data[1], $data[2])) {
                    list($this->items, $this->rules, $this->parents) = $data;
                    return true;
                }
                $promises = [
                    //Items
                    (new Query())->from($this->itemTable)->all($this->db),
                    //Rules
                    (new Query())->from($this->ruleTable)->all($this->db),
                    //Children
                    (new Query())->from($this->itemChildTable)->all($this->db),
                ];

                return all($promises)
                    ->then(function($results = []) {
                        $items = isset($results[0]) ? $results[0] : [];
                        $rules = isset($results[1]) ? $results[1] : [];
                        $itemsChildren = isset($results[2]) ? $results[2] : [];

                        $this->items = [];
                        foreach ($items as $row) {
                            $this->items[$row['name']] = $this->populateItem($row);
                        }

                        $this->rules = [];
                        foreach ($rules as $row) {
                            $data = $row['data'];
                            if (is_resource($data)) {
                                $data = stream_get_contents($data);
                            }
                            $this->rules[$row['name']] = unserialize($data);
                        }

                        $this->parents = [];
                        foreach ($itemsChildren as $row) {
                            if (isset($this->items[$row['child']])) {
                                $this->parents[$row['child']][] = $row['parent'];
                            }
                        }

                        return $this->cache->set($this->cacheKey, [$this->items, $this->rules, $this->parents]);
                    });
            });
    }
public function loadFromCache()
    {
        if ($this->items !== null || !$this->cache instanceof ExtendedCacheInterface) {
            return resolve(true);
        }

        return $this->cache->get($this->cacheKey, [])
            ->then(function($data) {
                if (is_array($data) && isset($data[0], $data[1], $data[2])) {
                    list($this->items, $this->rules, $this->parents) = $data;
                    return true;
                }
                $promises = [
                    //Items
                    (new Query())->from($this->itemTable)->all($this->db),
                    //Rules
                    (new Query())->from($this->ruleTable)->all($this->db),
                    //Children
                    (new Query())->from($this->itemChildTable)->all($this->db),
                ];

                return all($promises)
                    ->then(function($results = []) {
                        $items = isset($results[0]) ? $results[0] : [];
                        $rules = isset($results[1]) ? $results[1] : [];
                        $itemsChildren = isset($results[2]) ? $results[2] : [];

                        $this->items = [];
                        foreach ($items as $row) {
                            $this->items[$row['name']] = $this->populateItem($row);
                        }

                        $this->rules = [];
                        foreach ($rules as $row) {
                            $data = $row['data'];
                            if (is_resource($data)) {
                                $data = stream_get_contents($data);
                            }
                            $this->rules[$row['name']] = unserialize($data);
                        }

                        $this->parents = [];
                        foreach ($itemsChildren as $row) {
                            if (isset($this->items[$row['child']])) {
                                $this->parents[$row['child']][] = $row['parent'];
                            }
                        }

                        return $this->cache->set($this->cacheKey, [$this->items, $this->rules, $this->parents]);
                    });
            });
    }
Load/save cache
@return ExtendedPromiseInterface