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

Use an optional image dimensions cache #25

Closed
wants to merge 7 commits into from

Conversation

ausi
Copy link
Member

@ausi ausi commented Nov 19, 2016

A single request in Contao causes many (hundreds) calls to Image::getDimensions(), e.g. for every icon shown on a backend page. A cache for the dimensions off all images would be a big performance boost.

@contao/developers does this implementation make sense that way?
If yes, I can make a pull request to the core-bundle to use the cache there.

@aschempp
Copy link
Member

You should not add new methods to a stable interface, probably use a CacheableImageInterface?

Or maybe the methods dont need to be in the interface because they are not supposed to be used externally (except for dependency injection).

@aschempp
Copy link
Member

Also, being only dependency injection would mean that the component can run with or without cache, which I think is a cool feature. But it needs a readme 😉

@ausi
Copy link
Member Author

ausi commented Nov 20, 2016

You should not add new methods to a stable interface

I think this should not be a problem if we release a new version 0.4.0.

probably use a CacheableImageInterface?

That would have the benefit to make the cache support for an implementor of the ImageInterface optional, but on the other hand it makes things more complicated and the library more bloated I think.

Or maybe the methods dont need to be in the interface because they are not supposed to be used externally (except for dependency injection).

The image library itself doesn’t create a cache, so the methods have to be used externally to make use of a cache.

Also, being only dependency injection would mean that the component can run with or without cache, which I think is a cool feature.

That’s the case already.

But it needs a readme 😉

I will add :)

@ausi ausi force-pushed the feature/image-dimensions-cache branch from 77d94a7 to b94e962 Compare November 20, 2016 15:43
@ausi ausi changed the base branch from master to hotfix/0.3.1 November 20, 2016 15:44
@leofeyer
Copy link
Member

You should not add new methods to a stable interface, probably use a CacheableImageInterface?

That's not a problem IMHO:

Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.

@aschempp
Copy link
Member

The image library itself doesn’t create a cache, so the methods have to be used externally to make use of a cache.

I don't understand that. If I do not setter-inject an image dimensions cache, the getDimensions method will simply fall back to not using a cache (because it's null). Therefore it's an optional dependency, and nothing that should be in the interface because it is not required for the functionality.

@ausi
Copy link
Member Author

ausi commented Nov 21, 2016

Take a look at Resizer.php:147 for example, it expects that ImageInterface::getDimensionsCache() is available, which can only be guaranteed if it’s in the interface. So either the ImageInterface gets the getDimensionsCache method or we add a new interface with that method which would bloat the library for no benefit.

If such a case happens in the future, going with a new interface would be the only option because of BC. But we don’t yet have to be BC with this library IMO.

@aschempp
Copy link
Member

The resizer uses the concrete class, so it knows the method is there. The interface is for injection and methods to use, setting the cache layer is not relevant for that.

@ausi
Copy link
Member Author

ausi commented Nov 21, 2016

On that line: Resizer.php:147 $image->getDimensionsCache() the $image refers to the interface, not the concrete class.

@ausi
Copy link
Member Author

ausi commented Nov 21, 2016

An alternative from @aschempp: Remove getDimensionsCache and setDimensionsCache from the ImageInterface and add a ImageInterface::clone($path) that can be used by the resizer in Resizer.php:147, did I get that right?

I think this could be a better solution and more flexible for future additions.

@ausi
Copy link
Member Author

ausi commented Nov 21, 2016

@contao/developers what do you think about the clone() method?

@leofeyer
Copy link
Member

I like it.

@ausi
Copy link
Member Author

ausi commented Nov 22, 2016

This is not the way we want to go, see contao/core-bundle#626 (comment)

@ausi ausi closed this Nov 22, 2016
@ausi ausi deleted the feature/image-dimensions-cache branch December 28, 2016 14:52
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

3 participants