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

files driver synchronisation #367

Closed
ghost opened this issue Oct 7, 2016 · 2 comments
Closed

files driver synchronisation #367

ghost opened this issue Oct 7, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 7, 2016

Hi,
first of all I want to thank you for the phpFastCache. I am making a decision what kind of cacheing framework to use with php and yours looks very intuitive and robust.

Nevertheless I did some local testing, mainly with the 'files' driver and I got some failures.

My testing code:

<?php
        require 'vendor/autoload.php';

        use phpFastCache\CacheManager;

        $fileCache = CacheManager::getInstance('files');
        $key = "product_page";

        $cachedItem = $fileCache->getItem($key);

        // there should be nothing in the cache.
        echo '<br/>';
        echo 'Stats size: ' . $fileCache->getStats()->getSize();
        echo '<br/>';
        echo 'Stats data: '. $fileCache->getStats()->getData();
        echo '<br/>';
        echo 'CachedItem key: ' . $cachedItem->getKey();
        echo '<br/>';
        echo 'CachedItem->get: ' . $cachedItem->get();

        echo '<br/><br/>';

        // cache some value
        $cachedItem->set("Some cached value");
        $fileCache->save($cachedItem);
        $fileCache->commit();
        echo 'Stats size: ' . $fileCache->getStats()->getSize();
        echo '<br/>';
        echo 'Stats data: '. $fileCache->getStats()->getData();
        echo '<br/>';
        echo 'CachedItem key: ' . $cachedItem->getKey();
        echo '<br/>';
        echo 'CachedItem->get: ' . $cachedItem->get();

        echo '<br/><br/>';

        // cache other value with the same key -> update
        $cachedItem->set("OTHER cached value");
        $fileCache->save($cachedItem);
        $fileCache->commit();
        echo 'Stats size: ' . $fileCache->getStats()->getSize();
        echo '<br/>';
        echo 'Stats data: '. $fileCache->getStats()->getData();
        echo '<br/>';
        echo 'CachedItem key: ' . $cachedItem->getKey();
        echo '<br/>';
        echo 'CachedItem->get: ' . $cachedItem->get();

        // clear at the end.
        $cleared = $fileCache->clear();

        ?>

When I load the page, everything seems to be OK. Anytime. But when I quickly hit the page at least 3 times(server is probabl trying to load from and clean the cache at the same time) I randomly got this failures.
1.
Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(C:\xampp\tmp\phpfastcache\localhost\files,C:\xampp\tmp\phpfastcache\localhost\files): System cant find specified path. (code: 3) in C:\xampp\htdocs\Task\vendor\phpfastcache\phpfastcache\src\phpFastCache\Util\Directory.php:56 Stack trace: #0 C:\xampp\htdocs\Task\vendor\phpfastcache\phpfastcache\src\phpFastCache\Util\Directory.php(56): RecursiveDirectoryIterator->__construct('C:\xampp\tmp\ph...') #1 C:\xampp\htdocs\Task\vendor\phpfastcache\phpfastcache\src\phpFastCache\Drivers\Files\Driver.php(235): phpFastCache\Util\Directory::getFileCount('C:\xampp\tmp\ph...') #2 C:\xampp\htdocs\Task\index.php(33): phpFastCache\Drivers\Files\Driver->getStats() #3 {main} thrown in C:\xampp\htdocs\Task\vendor\phpfastcache\phpfastcache\src\phpFastCache\Util\Directory.php on line 56

OR

2.
Fatal error: Uncaught phpFastCache\Exceptions\phpFastCacheDriverException: Can't read PATH:C:\xampp\tmp\phpfastcache\localhost\files in C:\xampp\htdocs\Task\vendor\phpfastcache\phpfastcache\src\phpFastCache\Drivers\Files\Driver.php:229 Stack trace: #0 C:\xampp\htdocs\Task\index.php(45): phpFastCache\Drivers\Files\Driver->getStats() #1 {main} thrown in C:\xampp\htdocs\Task\vendor\phpfastcache\phpfastcache\src\phpFastCache\Drivers\Files\Driver.php on line 229

It comes the file synchronisation issue to my mind as the possible root cause of that random issue.
I've found this article with my quick investigation. I tried to wrap it with iterator_to_array() but without a change.
What do you think?

Thanks.
Milos

@Geolim4
Copy link
Member

Geolim4 commented Oct 7, 2016

Hi MilosNan,

You may forgot to specify the TTL:
$cachedItem->set("OTHER cached value")->expireAfter(300);

Another possible case is that your server make use of "Delayed write" which can be the cause of this issue.
I tried your code i cannot reproduce the issue for now.

Cheers,
Georges

@Geolim4
Copy link
Member

Geolim4 commented Oct 11, 2016

Hello @authorname,

I’m closing this pull request for now because of (inactivity / outdated code / …).

You can always reopen it though! :)
Please (update the pull request / rebase your branch / clarify …).

Regards,
Georges.L

@Geolim4 Geolim4 closed this as completed Oct 11, 2016
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

1 participant