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

Is it possible to disable cache? #30

Closed
sagikazarmark opened this issue Jan 30, 2015 · 12 comments
Closed

Is it possible to disable cache? #30

sagikazarmark opened this issue Jan 30, 2015 · 12 comments

Comments

@sagikazarmark
Copy link
Member

I want to give varnish a try, and I don't want files stored twice in my filesystem. Is it possible to disable cache?

@reinink
Copy link
Contributor

reinink commented Jan 30, 2015

Not at the moment, no. I had no idea anyone would ever want to that, but that makes sense if you're using Varnish. Can you leave this with me to add a new method for this? For the time being maybe just save the cached files to sys_get_temp_dir()?

@sagikazarmark
Copy link
Member Author

I probably found the solution. IIRC there is a null adapter in flysystem. That might work.

@reinink
Copy link
Contributor

reinink commented Jan 30, 2015

Haha, yep, that would probably work too. ;)

@xtrasmal
Copy link

Is this repo free for pull requests? I'd like to add something like this:

Current situation:

    /**
     * Get the source file system.
     * @return FilesystemInterface The source file system.
     */
    public function getSource()
    {
        $source = null;

        if (isset($this->config['source'])) {
            $source = $this->config['source'];
        }

        if (is_string($source)) {
            return new Filesystem(new Local($source));
        }

        if ($source instanceof FilesystemInterface) {
            return $source;
        }

        throw new InvalidArgumentException('Invalid `source` parameter.');
    }

Preferred situation:

    /**
     * Get the source file system.
     * @return FilesystemInterface The source file system.
     */
    public function getSource()
    {
        $source = null;

        if (isset($this->config['source'])) {
            $source = $this->config['source'];
        }

        if (is_string($source)) {
            return new Filesystem($this->adapter($source, $adapterclass));
        }

        if ($source instanceof FilesystemInterface) {
            return $source;
        }

        throw new InvalidArgumentException('Invalid `source` parameter.');
    }
// Add the source and the adapter, f.e. 'League\Flysystem\Adapter\Null'
    public function adapter($source, $class)
    {
        return new $class($source);
    }

@reinink
Copy link
Contributor

reinink commented Feb 25, 2015

Hi @xtrasmal, can you explain to me exactly what you're trying to do? I'm sort of confused. If you're simply trying to pass the Null adapter to the Glide factory you can just do this:

$server = League\Glide\ServerFactory::create([
    'source' => 'path/to/source/folder',
    'cache' => new League\Flysystem\Adapter\Null(),
]);

@ghost
Copy link

ghost commented Mar 3, 2015

Hi @reinink, passing an instance of Flysystem's NullAdapter (there is no Null) as you suggested does not work:

InvalidArgumentException in ServerFactory.php line 90:
Invalid `cache` parameter.

I believe it has to do with the following check on line 86 of ServerFactory.php just before the InvalidArgumentException gets thrown:

if ($cache instanceof FilesystemInterface) {
    return $cache;
}

Because: NullAdapter extends AbstractAdapter which implements AdapterInterface which extends ReadInterface. So it is not an instance of FilesystemInterface.

I believe this is a bug as there is currently no way to turn off caching, which I would like to so as to let a CDN handle caching managed by headers.

Thoughts?

@reinink
Copy link
Contributor

reinink commented Mar 3, 2015

Yeah, agreed, I'll add the option to disable the cache in an upcoming release.

@shyam-achuthan
Copy link

Is there a way to delete the cached files for a particular image?
Say i have a profile image getting uploaded to the S3 which is scaled at different ui, when the user changes the image it wont change the image endpoints but glide actually serves the old cached images based on old requests.

@ghost
Copy link

ghost commented Mar 20, 2015

@shyam-achuthan What you're describing is cache invalidation; something that is discussed in another issue.

From my understanding, there is currently no cache invalidation handling in Glide. I submitted a pull request to allow disabling of the cache so that caching - and invalidation - could simply be handled by another layer like a CDN (e.g. Amazon CloudFront) or a reverse proxy (e.g. Nginx).

@xtrasmal
Copy link

cache invalidation 👍

@xtrasmal
Copy link

That is my problem

Op 20 mrt. 2015 om 14:17 heeft "Shyam Achuthan" notifications@github.com het volgende geschreven:

Is there a way to delete the cached files for a particular image?
Say i have a profile image getting uploaded to the S3 which is scaled at different ui, when the user changes the image it wont change the image endpoints but glide actually serves the old cached images based on old requests.


Reply to this email directly or view it on GitHub.

Met vriendelijke groet, With kind regards,

Xander Smalbil

Netbulae Virtualization Experts


Tel: 053 20 30 270  info@netbulae.eu    Staalsteden 4-3A    KvK 08198180
Fax: 053 20 30 271  www.netbulae.eu     7547 TA Enschede    BTW NL821234584B01

@reinink
Copy link
Contributor

reinink commented Jun 15, 2015

Hey all, I've finally got a good solution to this cache disabling problem. See #56.

@reinink reinink closed this as completed Jun 15, 2015
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

4 participants