public function attributes($bundle = null)
    {
        $key = empty($bundle) ? '@all' : $bundle;
        if (isset($this->_attributes[$key])) {
            return $this->_attributes[$key];
        }

        $this->_attributes[$key] = [];
        $cacheKey = $this->_table->table() . '_' . $key;
        $attrs = Cache::read($cacheKey, 'eav_table_attrs');

        if (empty($attrs)) {
            $conditions = ['EavAttributes.table_alias' => $this->_table->table()];
            if (!empty($bundle)) {
                $conditions['EavAttributes.bundle'] = $bundle;
            }

            $attrs = TableRegistry::get('Eav.EavAttributes')
                ->find()
                ->where($conditions)
                ->all()
                ->toArray();

            Cache::write($cacheKey, $attrs, 'eav_table_attrs');
        }

        foreach ($attrs as $attr) {
            $this->_attributes[$key][$attr->get('name')] = $attr;
        }

        return $this->attributes($bundle);
    }