PHPSocialNetwork / phpfastcache

A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
https://www.phpfastcache.com
MIT License
2.38k stars 451 forks source link

secureFileManipulation clarification about path option #785

Closed DePalmo closed 3 years ago

DePalmo commented 3 years ago

Configuration

My question I init the library like this:

try {
    CacheManager::setDefaultConfig(new Config([
        "path" => dir_root . '_cache',
        "itemDetailedDate" => false,
        "secureFileManipulation" => true
    ]));
} catch (PhpfastcacheInvalidConfigurationException $e) {
} catch (ReflectionException $e) {
}
$cache = new Psr16Adapter('Files');

Then use it like this:

$translation = $this->cache->get('translation');
$this->cache->set('translation', $translation);

Up until I started using secureFileManipulation, I always saw a folder _cache being created and used, but when I set secureFileManipulation to true, that folder is not being created and I can't find cached files. I tested the caching code and it appears working, but the website feels a bit slower than before. Please note that I am caching some strings and my code would call database multiple times, so with your caching library, this was speed up by a lot.

So my question is: is it normal that I do not see _cache folder being created and used, when I am using secureFileManipulation? If yes, when are the files then stored?

github-actions[bot] commented 3 years ago

Hello curious contributor ! Since it seems to be your first contribution, make sure that you've been:

Geolim4 commented 3 years ago

Yeah,

This option will make advanced file verification before writing the file on the disk, this is usually enabled when there's a high conflict risk due to an intense I/O activity.

Except if you think that there's a risk of failing filesystem this option is not very useful.

It uses a mechanism of "temporary name then write and rename" instead of "direct file write".

So this behavior is totally normal and you may furtively notice a sub-folder called "tmp_xxxxxxxxxxx" during write operations.

Cheers, Georges

DePalmo commented 3 years ago

Thank you for your response. The problem is that after the code executes without any issues, there's no _cache folder at all. It's not being created and no tmp_ folder is there either.

Geolim4 commented 3 years ago

The tmp_ file (sorry) is only created during script execution then immediately renamed to its true name.

This is why this can slow down a bit your website.