Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with cache (tested on disk and session) #85

Open
09173732546 opened this issue Feb 21, 2024 · 4 comments
Open

Issue with cache (tested on disk and session) #85

09173732546 opened this issue Feb 21, 2024 · 4 comments

Comments

@09173732546
Copy link

09173732546 commented Feb 21, 2024

I have this error

First load: (no cache yet) - page will display data

Subsequent: (cached) - Warning: Invalid argument supplied for foreach() in /www/wwwroot/xxxxxx/xxxxx.php on line 71

Debug shows that it has cached the query, whether disk or session . But it wont render in foreach, print_r result is 0.

Im using Zebra_Session with Zebra_Database $link

// Retrieve threads from the database
#$threads = $db->query('SELECT * FROM threads ORDER BY timestamp DESC LIMIT ' . $offset . ', ' . $itemsPerPage, 300);
$threads = $db->select(
    '*',
    'threads',
    '',
    '',
    'timestamp DESC',
    "{$offset}, {$itemsPerPage}",
	300
);
    <?php foreach ($threads as $thread) : ?>
      ...
     <p>Timestamp: <?php echo date('Y-m-d H:i:s', $thread['timestamp']); ?></p>
     <p><?php echo $thread['content']; ?></p>
     ...
     <?php endforeach; ?>

Its been a while i not used ZDB maybe i have error in the cache syntax in queries.

@stefangabos
Copy link
Owner

i can't reproduce the error. here's what i am doing

$db->query('
    SELECT
        Name
    FROM
        city
    WHERE
        CountryCode = ?
    ORDER BY
        Name
', array($country_code), 300);

while ($row = $db->fetch_assoc()) {
    print_r('<pre>');
    print_r($row);
    print_r('</pre>');
}

@stefangabos
Copy link
Owner

...actually, looking at your code, in the commented out example, the one where you are using query, 300 is not in the correct position - it should be 3rd but it is second; see docs
in your example using select, this {$offset}, {$itemsPerPage} makes no sense as it should rather be [$offset, $itemsPerPage]; again, see docs

@09173732546
Copy link
Author

09173732546 commented Feb 22, 2024

...actually, looking at your code, in the commented out example, the one where you are using query, 300 is not in the correct position - it should be 3rd but it is second; see docs in your example using select, this {$offset}, {$itemsPerPage} makes no sense as it should rather be [$offset, $itemsPerPage]; again, see docs

regarding the commented out query() - my bad, i updated it the last moment, yes it is indeed on the 3rd place. moving to my issue:

Issue 1: foreach() cannot handle cached data

Database
image

query()
image

foreach()
image

First run - "not yet cached"
image

First log - "not yet cached"
image

Subsequent run - "cached"
image

Subsequent run log - "cached"
image

Comment: The foreach() error only appear if i use cache. As of posting i will be using while() but i hope you can look into that also. Cache works on while() but not on foreach()

Issue 2: select() as per your suggestion to use [$offset, $itemsPerPage]:

image

First run:
image

Comment: If i use {$offset}, {$itemsPerPage} (currently using) it will run OK.

Issue 3: Cache works only using session

I am using /tmp/ and that path works with other php library.
image

Comment: using disk will throw: Could not cache query. Make sure path exists and is writable... to use disk i need to place the cache folder in the directory of Zebra_Database class itself

using php 7.4 on dev and live

@stefangabos thanks

@stefangabos
Copy link
Owner

hey, did you manage to get this working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants