Code Monkey home page Code Monkey logo

Comments (20)

h4cc avatar h4cc commented on September 13, 2024

If there are multiple ways of implementing the CacheCleanup, it could be integrated by using the Strategy Pattern.
Some default strategy like OlderThanCleanup or NoCleanup can then be provided by glide.

from glide.

reinink avatar reinink commented on September 13, 2024

@h4cc That's probably a good idea actually.

I've thought of another way of doing this. Glide could keep an access log in the cache file system, which could be then used by a cleanup job later. This access log would provide access dates in addition to just creation dates.

from glide.

barryvdh avatar barryvdh commented on September 13, 2024

@reinink and what about when the source image changes?

For example, I have a filebrowser where I can resize/rotate etc some files. But changes aren't shown because the file is cached.
A solution could be checking the time the file has changed and invalidate the cache if needed, but this causes extra calls..

from glide.

reinink avatar reinink commented on September 13, 2024

I'm actually like the idea I'm seeing in PR #60.

Basically, we could allow folks to override how the cached filename is generated. This would allow you to group all manipulations for a specific source image into a specific folder. Then, if you delete that source folder, you can easily delete all the cached variations. Something like this:

$server->setCachePathFilter(function (Request $request, $path) {
    // modify $path
    return $path;
});

At this point I'm just not sure a closure is the best way (it seems a little complicated), or if we just abstract the cache path generation to a new class, with a interface.

Whatever the case, I think I'm going to do something here. I just need to work out the simplest way, and do some testing.

from glide.

reinink avatar reinink commented on September 13, 2024

Or, another idea, why don't we just automatically organized the cached images into folders, and the folders will simply be the source name. For example:

// Source:
/source/kayaks.jpg
/source/logos/logo.png

// Cache:
/cache/kayaks.jpg/md5-cache-filename
/cache/kayaks.jpg/md5-cache-filename
/cache/kayaks.jpg/md5-cache-filename
/cache/logos/logo.png/md5-cache-filename
/cache/logos/logo.png/md5-cache-filename
/cache/logos/logo.png/md5-cache-filename

That would make it really easy to delete the cache for any particular source image. For example:

$cache->deleteDir('kayaks.jpg');

Thoughts?

from glide.

schmidex avatar schmidex commented on September 13, 2024

I like that ;-)
This storage structure and a delteCache($source) method on the Server class.

from glide.

ingro avatar ingro commented on September 13, 2024

That would be great, a way to clear the cache only for a specific image it's the missing piece for us to start using Glide in production!

from glide.

reinink avatar reinink commented on September 13, 2024

@schmidex @ingro Glad you like! Coming soon to the next release of Glide. Hopefully within the next few weeks.

from glide.

ADmad avatar ADmad commented on September 13, 2024

why don't we just automatically organized the cached images into folders, and the folders will simply be the source name.

👍 💯

from glide.

joshrhykerd avatar joshrhykerd commented on September 13, 2024

I really like the idea of being able to clean up the cache files using folders by source name. Has there been any progress on this enhancement yet? Thanks for the great library!

from glide.

reinink avatar reinink commented on September 13, 2024

@joshrhykerd Glad you like! And yes, this feature has been built and will be available as soon as I release version 1.0, which is really any day now. You can see this feature mentioned in the WIP docs, here.

from glide.

joshrhykerd avatar joshrhykerd commented on September 13, 2024

I hate to ask, but there isn't any development branch or anything anywhere with this functionality already built in is there? I'm in a slight predicament now where I neeeeeed this ability. lol Again thanks again for this great library!

from glide.

reinink avatar reinink commented on September 13, 2024

@joshrhykerd For sure, just use dev-master. In your Composer file:

{
    "require": {
        "league/glide": "dev-master"
    }
}

Note that you'll likely also want to use a framework adapter, to make getting responses back easier. I originally had these built right in, but I recent split them all into separate packages. Add the framework adapter of your choice in the same way:

{
    "require": {
        "league/glide-symfony": "dev-master"
    }
}

And then just follow the docs for how to setup the response factory. It will look something like this:

$server = League\Glide\ServerFactory::create([
    'response' => new League\Glide\Responses\SymfonyResponseFactory()
]);

Just be aware that you're using development code. Be sure to switch from dev-master to a tagged release as soon as one is available. Good luck!

from glide.

joshrhykerd avatar joshrhykerd commented on September 13, 2024

@reinink Thanks!

from glide.

joshrhykerd avatar joshrhykerd commented on September 13, 2024

@reinink I'm not sure if this is a bug or not, but when I call

$server->deleteCache($filename);

with just the source filename it doesn't seem to work. I have to also include the server cache_path_prefix.

$server->deleteCache($server->getCachePathPrefix() . DS . $filename);

Should it automatically be including the cache_path_prefix for me? or am I doing something wrong?

from glide.

reinink avatar reinink commented on September 13, 2024

Hmm, maybe it's broken. It was working, but I still need to write tests for this. Honestly, for now you can just use Flysystem directly. For example:

$cache->deleteDir('path/to/directory/to/delete');

from glide.

reinink avatar reinink commented on September 13, 2024

This feature should now be fixed. (5ededae)

from glide.

reinink avatar reinink commented on September 13, 2024

Closing this ticket. These changes have been merged into the master branch and will be tagged shortly when I release v1.0! Hopefully not long now.

from glide.

argb avatar argb commented on September 13, 2024

@reinink Looking forward to the release of version 1.0,and when ? :D

from glide.

papalardo avatar papalardo commented on September 13, 2024

The method deleteCache not works with me.

I did need to do this way:

$server = app(GlideServer::class);

// $server->deleteCache($imagePath); // not works
// $server->deleteCache($server->getCachePathPrefix() . "/" . $imagePath); // not works
 
Storage::disk('images')->deleteDirectory($server->getCachePathPrefix() . "/" . $imagePath); // works

from glide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.