php - CakePHP 3: Caching database object in component -


i'm trying save database object (plugin) component cakephp cache.

this works ( note toarray() )

        $domains = cache::read('domains', 'long');          if ($domains === false) {              $domainstable = tableregistry::get('domainmanager.domains');             $domains = $domainstable->find('all', ['fields' => ['id', 'name']]);             $domains = $domains->toarray();              cache::write('domains', $domains, 'long');             return $domains;         } 

but fails:

        $domains = cache::read('domains', 'long');          if ($domains === false) {          $domainstable = tableregistry::get('domainmanager.domains');         $domains = $domainstable->find('all', ['fields' => ['id', 'name']]);          cache::write('domains', $domains, 'long');         return $domains;     } 

the error given cakephp error: cannot serialize or unserialize pdo instances

sorry if i'm doing wrong, switched cake2 cake3 , nothing find in documentation.

thanks glues!

the find function not return results, returns query object can use fetch results. calling toarray on retrieve entities , give can cache. (it can confusing, toarray used convert entities arrays in other situations.)


Comments