# What is the naming convention for the cached PHP files?

**URL:** https://discourse.roots.io/t/what-is-the-naming-convention-for-the-cached-php-files/25061
**Category:** sage
**Tags:** sage10, acorn
**Created:** 2023-03-30T16:16:58Z
**Posts:** 2

## Post 1 by @JasonSalmon — 2023-03-30T16:16:58Z

Hello,

I was wondering how the cached files are named.

I ask because I’m trying to get Sage 10 to work with WP Engine and its multiple environments. I’ve created the following function (based on [this](https://discourse.roots.io/t/sage-10-with-acorn-wp-engine/23123)), which changes the default cache path location to /tmp/sage-cache/environment-name/. Before that, I also ensure that each location exists and is writable. This has been successful as i can clear the contents of /tmp/sage-cache/ and everything gets rebuilt. However, I do get cached files appearing in /tmp/sage-cache/, they’re not effecting what is being rendered on screen but I’d like to know where these files are coming from. If I could work out how the files are named I might be able to find out which environment they’re coming from and why.

```
/*
|--------------------------------------------------------------------------
| Fix Sage 10 to work with WP Engine environments
|--------------------------------------------------------------------------
|
| Override Acorn's view cache path to /tmp/sage-cache if the site
| is running on WP Engine environment.
|
| /tmp/sage-cache/framework/cache path should be present in WP Engine
| for Sage 10 to work.
|
| This is required for Sage 10 to work on WP Engine as the default
| view cache path is /<YourWordPressInstallRoot>/wp-content/cache/acorn/framework/views
| and with that default path, WP Engine doesn't allow PHP user to execute/write files in 
| that directory.
|
| filter ref: https://docs.roots.io/acorn/2.x/directory-structure/#advanced
| is_wpe ref: https://wpengine.com/support/determining-wp-engine-environment/
*/

if (function_exists('is_wpe') && is_wpe() == 1) {
  // Define the directory path
  $dir_path = '/tmp/sage-cache/'. PWP_NAME .'/framework/cache';

  // Check if the directory exists
  if (!file_exists($dir_path)) {
    // Create the directory if it doesn't exist
    if (!mkdir($dir_path, 0777, true)) {
      if (defined('WP_DEBUG') && WP_DEBUG) {
         // If WP_DEBUG is enabled, log the error to the debug log
        error_log('Failed to create directory: ' . $dir_path);
      }
    }
  }

  // Check if the directory is writable
  if (!is_writable($dir_path)) {
    // Make the directory writable if it's not already
    if (!chmod($dir_path, 0777)) {
      if (defined('WP_DEBUG') && WP_DEBUG) {
        // If WP_DEBUG is enabled, log the error to the debug log
        error_log('Failed to make directory writable: ' . $dir_path);
      }
    }
  }

  //Changes the default cache path
  add_filter('acorn/paths.storage', function ($path) {
    return '/tmp/sage-cache/'. PWP_NAME .'';
  });
}
```

Any help on this would be apricated

---

## Post 2 by @strarsis — 2023-04-13T16:00:25Z

Edit: In the Illuminate Blade compiler there is this function that generates the path for a compiled view file:

> <https://github.com/illuminate/view/blob/183ad8f4393a5b0c16bb1868be8471f208dab112/Compilers/Compiler.php#L84>

Note that `acorn` `3.1.0` (current version) [uses `illuminate/view` `9.47`](https://github.com/roots/acorn/blob/2ccffc169f9dba05499f7dbb6e2d30f2809312de/composer.json#L57),  
hence I linked to the function for `9.47`.

In later releases of `illuminate/view` (as `10.7.1`) the code for generating the file path actually has changed ([https://github.com/illuminate/view/blob/81c2d4e35774714ccd53f3b8fba2afe7ee093609/Compilers/Compiler.php#L84](https://github.com/illuminate/view/blob/81c2d4e35774714ccd53f3b8fba2afe7ee093609/Compilers/Compiler.php#L84))!  
So you may want to call that function from the `Illuminate\View\Compilers\Compiler` class, and not just hard-copy its logic, to future-proof your code.
