2

I have a project in which I have a large array with locations having certain timezones.

I do not wish to use a database because that would mean too many database hits and writing Yet Another Caching Mechanism to prevent database hits.

So I made it into a php file with arrays. Currently it's 2.5mb on disc.
I could trim down the arrays to save on some info I don't need at this point in time but might in the future(geographic location, city names, altitude etc..)

Since I have opcache enabled, I am hoping that opcache will cache this very large file, saving the disc hits, keeping the data readily available.

can someone confirm opcache will also cache this large 2.5mb file? or give me a method to test/verify this file is cached?

Tschallacka
  • 27,901
  • 14
  • 88
  • 133
  • You could just use something like [Redis](https://redis.io/) if you really wanted to. – Andrei Jan 09 '18 at 12:52
  • 2
    Tools like @PeeHaa's [OpcacheGUI](https://github.com/PeeHaa/OpCacheGUI) can tell you exactly what is stored in OpCache... but there is no reason why Opcache can't hold a 2.5MB file – Mark Baker Jan 09 '18 at 12:53
  • I already have memcache, but this is static data that will not change, doesn't need to be modified and a php array is sufficient. – Tschallacka Jan 09 '18 at 12:53

1 Answers1

0

Yes, opcache will cache it.

By looking at the code from the tool commented by MarkBaker I was able to get this simple verify script out to see if the file is cached or not.

Al you need is the absolute path to the file, and then you can easily check if it's cached or not.

<pre><?php 
$status = opcache_get_status();
$scripts = $status['scripts'];
$file = 'F:\cmslib-dev\include\lib\locations\Locations.php';

if(array_key_exists($file, $scripts)) {
    var_dump($scripts[$file]);
}
else {
    echo "$file is not cached";
}
?>
</pre>
Tschallacka
  • 27,901
  • 14
  • 88
  • 133