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

Cache files with different paths differently #6444

Merged

Conversation

jonassiewertsen
Copy link
Contributor

An Issue came up on Discord:

class ServiceProvider extends AddonServiceProvider
{
    protected $stylesheets = [
        __DIR__.'/../resources/css/admin-styler-base.css'
        // Under the hood, Statamic::style() will be called. The name     
        // `admin-styler` will be used automatically as  name, as it's the addon name.
        // The cache prefix will be::
        // "statamic-{$extension}-{$name}"
        // In that case `statamic-css-admin-styler`
        // @see https://github.com/statamic/cms/pull/6312/files#diff-a932c529bea3a9e695fb0306ae4635bda104d78b85cb8eb7bc15de11bc2f44d7R397
    ];

    public function boot()
    {
        parent::boot();

        Statamic::style('admin-styler', 'admin-styler-custom');
        // The name is `admin-styler` as well, so the cache kicks in and will deliver the cached file instead.
    }
}

The fix does allow for assets with the same name but different paths.

src/Statamic.php Outdated Show resolved Hide resolved
Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to use an md5 hash of the path. The trimming on the path seemed a little arbitrary, but using a hash just makes it use the path but as a shorter string we don't care about reading.

@jasonvarga jasonvarga merged commit 51908b0 into statamic:3.3 Aug 11, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants