We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37380
    • 20 Posts
    Using the default cache partition of the xPDOCacheManager to cache some API calls in a snippet.

    And it silently crashes every time I fetch the cached data.

    This is my code:

    $apiData = array();
    
    // The data is returned as an array. It's a 3-level deep array with objects and arrays in it.
    $apiData = $modx->cacheManager->get('books');
    
    if (empty($apiData)) {
    	$apiData = apiRequest("titles");
    	// Caches data for 1h
    	$modx->cacheManager->set('books', $apiData, 3600);
    }
    


    This is a sample of the data being retrieved by the apiRequest() and later saved into the cache partition:

    object(stdClass)#83 (1) {
      ["result"]=>
      object(stdClass)#84 (2) {
        ["data"]=>
        array(21) {
          [0]=>
          object(stdClass)#85 (6) {
            ["id"]=>
            string(4) "2179"
            ["author"]=>
            string(8) "Author A"
            ["title"]=>
            string(7) "Title A"
            ["year"]=>
            string(4) "1990"
            ["type"]=>
            string(4) "book"
          }
          [1]=>
          object(stdClass)#86 (6) {
            ["id"]=>
            string(4) "2180"
            ["author"]=>
            string(8) "Author B"
            ["title"]=>
            string(7) "Title B"
            ["year"]=>
            string(4) "1991"
            ["type"]=>
            string(4) "ebook"
          }
          ...
          ...
    


    I have tested the same code with long strings of data and it works. I wonder, if this issue is caused by saving the wrong type of data, its size being too big (<1KB), etc.

    Some help would be greatly appreciate it. Thank you! [ed. note: oriolsabate last edited this post 9 years, 4 months ago.]
      • 37380
      • 20 Posts
      I converted the data into an associative array and simplified it by reducing its depth and now it works.

      I still wonder why..