Giter Site home page Giter Site logo

friendsofsymfony / foshttpcachebundle Goto Github PK

View Code? Open in Web Editor NEW
429.0 429.0 80.0 1.72 MB

Use the FOSHttpCache library in your Symfony projects

Home Page: http://foshttpcachebundle.readthedocs.io

License: Other

PHP 96.88% Makefile 1.49% Python 1.60% VCL 0.02% Twig 0.02%
cache http php symfony symfony-bundle

foshttpcachebundle's People

Contributors

alexander-schranz avatar andrerom avatar chtipepere avatar dbu avatar ddeboer avatar demigodcode avatar digitalkaoz avatar dunglas avatar emodric avatar gimler avatar hpatoio avatar j0k3r avatar jderusse avatar jean-beru avatar jnonon avatar joelwurtz avatar lolautruche avatar lsmith77 avatar onexhovia avatar snc avatar stof avatar tft7000 avatar tobion avatar toflar avatar usu avatar wesnick avatar wickedone avatar xwb avatar yoann-tyt avatar zlatio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

foshttpcachebundle's Issues

split into FOSHttpCache and FOSHttpCacheBundle?

actually the whole code about cache invalidation is not specific to symfony, but could run without. maybe it would make sense to split everything non-symfony into a component and have the bundle just provide the DI configuration and the request listeners and similar symfony related functionality.

now would be a good time to do that, as the namespace changes are a BC break for everybody anyways. doing it later would be a pain as we would change namespaces.

Refresh annotation

An annotation to refresh paths/routes is still missing:

  • either @Refresh
  • or add a refresh param (default = false) to invalidateRoute and invalidatePath; this option is cleaner and has my preference.

Support invalidation with Symfony reverse proxy

Although Varnish makes more sense for any serious caching, it could be nice to support the Symfony reverse proxy as well, for out of the box caching.

Note: There is now a kernel provided in this bundle to support the user context with the reverse proxy. But no cache invalidation as of yet.

This issue is an archive of the original discussion. See HttpCache label issues for a list of all topics.

configuration reference

the documentation should contain a configuration reference interlinked with a chapter on each feature that introduces to the why and how with minimal configuration examples. like the symfony and symfony cmf doc does with the Reference section and the chapters in the "Bundles" section. for us, it could be "Features" and "Configuration" i think.

see also the discussion in #92

Change the property visibility to private

Currently, everything uses protected properties in the bundle. This means that all properties are potential extension points, and a change on them will be a BC break.

As we want to follow semver, I think we should rather use the private visibility for properties and switch to protected only for places where we decide to expose a supported extension point. This will make thing easier to manage BC. A request to increase the visibility will need to be justified with a use case for the extension point (allowing us to decide whether it is the right way to provide such extension point).

Note that this rule will be common for our users, as it is the rule applied in Symfony itself.

what do you think about it ?

Allow override of request cache headers

In our app we'd like to control all http caching using FOSHttpCache, we've found that some bundles add default cache headers that we would like to override.
It would be nice to have a global setting like:

force_header_overwrite: true | false

Or even a way of overriding just for one rule:

fos_http_cache:
    cache_control:
        rules:
            # only match login.example.com
            -
                match:
                    host: ^login.example.com$
                headers:
                    cache_control: { public: false, max_age: 0, s_maxage: 0, last_modified: "-1 hour" }
                    vary: [Accept-Encoding, Accept-Language]
                    force_overwrite: true | false

If this is something that is useful to the community I can implement it and do a PR.

Move bundle to FOS

Checklist:

  • remove repositories from composer.json
  • remove @dev
  • remove 'work in progress' from readme and repo description
  • check FOSHttpCache for links to the bundle. e.g. doc/conf.py

Manually set caching headers are overwritten

Our CacheControlSubscriber overrides any caching headers the user may have set manually ($response->setMaxAge() etc.), except in the case of Vary. @dbu Is this intended behaviour? If so, we should document it clearly.

remove hard dependency on guzzle

guzzle is only used with the varnish invalidator. we should move that from require to suggest and check in the DI extension if varnish is activated if guzzle is available.

annotation documentation expression language

i fear that the expression language example in the annotation doc are wrong. the TagSubscriber only passes in request and response, but not the parameters to the method that was called. if we can manage to provide the named parameters, that would be awesome. otherwise we should change the examples to use the request object.

i also got the impression that * @Tag(expression="'news-'~article.id") mentioned in
http://foshttpcachebundle.readthedocs.org/en/latest/tagging.html#invalidate-tags will not work. for me, expression language did not behave like twig, i had to write article.getId().

Add Nginx configuration

The bundle is still geared primarily towards Varnish. Let’s change this so it becomes possible to configure Nginx, too.

Release Tasks

Doc issues

Please add any doc issues to this list, so we don’t forget about them and we can fix them later in one go.

  • Fix dot in table
  • Improve introduction on index
  • 'One line description of project.'
  • search code for "todo"
  • Check if we cover all features.

Convert EventListeners to EventSubscribers

@ddeboer said in #42: We should also standardize whether we user EventListeners or EventSubscribers (we now have both). EventSubscribers are easier to configure, but are tied closer to Symfony because they have to implement EventSubscriberInterface. Which do you prefer?

and i think going for subscriber sounds right to me.

Support REST controller invalidation

Add a controller annotation and YML configuration option that invalidate all methods in a controller when they and their routes names follow a convention, such as the of the FOSRestBundle.

Vary cache per user role

The CacheAuthorizationListener listener returns immediately after Symfony's security check for HEAD requests. Currently, it returns an empty response. We can make the listener more useful, though, by returning a hash based on the user's roles. That hash can then be set as a custom header. If the caching proxy is then configured to vary on that header, different responses for different user roles could be cached. Additionally, you'd still be sure each user only sees content that he has access to (because of Symfony's security check).

The user hash should be definable by the user. Perhaps from configuration (include_role or something?) but preferably by throwing an event (build_user_hash or something) that the user can add a listener for. This bundle then has its own listener with some sane defaults.

This idea is inspired by the very nice context aware caching in ez Publish. But whereas their solution requires a Varnish module to be installed (CURL), I think our solution will work with plain VCL restart.

Cannot install using composer

Hi,
When I use your command (composer require friendsofsymfony/http-cache-bundle:@stable) to install the bundle, it shows the error:

Problem 1
- The requested package friendsofsymfony/http-cache-bundle could not be found in any version, there may be a typo in the package name.
Problem 2
- Installation request for symfony/framework-standard-edition 2.5.x-dev -> satisfiable by symfony/framework-standard-edition[2.5.x-dev].
- symfony/framework-standard-edition 2.5.x-dev requires friendsofsymfony/http-cache-bundle @stable -> no matching package found.

Please help me with this issues. Thanks

support varnish management port

instead of sending special requests to the varnish frontend (and have rules that check every request for being a purge from the webserver), one could also use the telnet interface to send purge requests.

the user of the bundle should be able to call the same methods whether he uses the frontend purge controller or the one using the administration port.

http://www.varnish-cache.org/docs/3.0/reference/varnishd.html#management-interface
http://www.varnish-cache.org/docs/2.1/reference/varnishd.html#management-interface

see also TODO in https://github.com/liip/CacheControlBundle/blob/master/Helper/Varnish.php

request tagging mechanisms

why is there a difference between annotations and the configuration for creating tag headers? could these not just be 2 different ways to tell the same tools what they have to do? or is that already the case?

cache header rule configuration cleanup

currently, we have a ton of match criteria for the rules mixed up with the header configuration in case this matches.

path: ^/$
host: ^login.example.com$
methods: [ GET, HEAD ]
unless_role: ROLE_NO_CACHE
...
controls: { public: false, max_age: 0, s_maxage: 0, last_modified: "-1 hour" }
vary: [Accept-Encoding, Accept-Language]

we maybe should group this:

match:
    path: ^/$
    host: ^login.example.com$
    methods: [ GET, HEAD ]
    unless_role: ROLE_NO_CACHE
    ...
controls: { public: false, max_age: 0, s_maxage: 0, last_modified: "-1 hour" }
vary: [Accept-Encoding, Accept-Language]

possibly with the option to specify just the path outside of the match and validation in configuration that you have exactly one of match or a path specified.

see also #33

Rename CacheProxy to ProxyClient

As discussed in #42, the naming is a bit off. Rename in the component and the bundle. This will be a hard BC break of course. If we can merge the nginx PR first, we could do the change in one go, otherwise we break it again.

for using in the bundle, i think it makes sense to have a proxy_client.varnish and other proxy_client.X and then define the alias from the DI class for default_proxy_client. that way some really complicated setup could even run both varnish and nginx or symfony built-in cache clients, and add his own services with the other clients.

Support multiple hosts

Currently, the bundle supports only one value for host. That's a bit silly, as an application could have multiple hostnames for which caches must be invalidated.

Add user context route automatically

As discussed elsewhere, our implementation of the user context functionality requires a route to be defined. We now tell users to add that route themselves. It would be more user-friendly to do that for them, probably based on a config parameter. If we change this, we should remember to update the docs accordingly.

Cache control unless_role filter

In the request matching to decide on cache rules, there is an unless_role option that skips the rule if the user is authorized and has a specific role. This only ever makes sense when nothing is cached or responses vary on the cookie, so can only really set the max-age. @lsmith77 explained that it was built in LiipCacheControlBundle to set no cache for admin users in a project.

This option feels weird to me. To cover the use case, a match_permission would make much more sense. Then we could do a granted check if there is a security context with a token and apply that rule if its granted.

Make cache invalidation more generic

Have concrete HTTP cache implementations implement interface PurgeInterface, and, optionally, BanInterface. For instance:

Should we copy the Varnish names (purge and ban) or stick to our own names, such as invalidateUrl and invalidateRegex or something like that?

Send invalidation requests in parallel

This is currently possible in the Driebit bundle, but that only supports purge requests. Allowing invalidation requests to be done in parallel becomes more complex when adding ban and refresh support.

Two options:

  1. A cache manager class that goes on top of our HTTP cache implementations (such as Varnish) collects all invalidation requests and then calls the corresponding methods on the Varnish class. This may be considered a clearer separation of concerns: the Varnish class shouldn't know anything about collecting requests but only about sending them. The Varnish interface becomes messier, though: purge(string[] $urls) (multiple URLs together), ban(string[] $urls) (but how to have custom headers per URL?). Maybe a custom Request that holds both URL and headers class could help here, so we get ban(Request[] $requests). Even then, it's impossible to combine all ban, purge and refresh requests together.
  2. Each HTTP cache implementation (Varnish, Nginx, …) itself does the request collection. This allows for cleaner interfaces: purge($url) (single URL), ban($url, $headers, …). This does mean more duplicate code, though, between the Varnish and Nginx classes. We could have an AbstractHttpCache class that takes care of queueing and flushing, of course.

Am I missing something?

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.