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

Feature Request: URI Exclusion Patterns for Client-Side Cache #498

Closed
raamdev opened this issue Jun 11, 2015 · 14 comments
Closed

Feature Request: URI Exclusion Patterns for Client-Side Cache #498

raamdev opened this issue Jun 11, 2015 · 14 comments
Assignees
Labels
Milestone

Comments

@raamdev
Copy link
Contributor

@raamdev raamdev commented Jun 11, 2015

It's currently possible to exclude certain URLs from being cached by ZenCache using ZenCache → Plugin Options → URI Exclusion Patterns, however when Client-Side Caching is enabled (ZenCache → Plugin Options → Client-Side Cache) the only way to exclude a particular URL from a client-side cache is to ensure that ?zcABC=0 is appended to the URL.

It would be nice if there were a few extra options inside the existing URI Exclusion Patterns panel (such as an option to "Also exclude these URLs from Client-Side Caching"), as well as an additional section with a box for listing URI Exclusion Patterns that should apply only to Client-Side Caching.


Support threads referencing this issue

@jaswrks
Copy link

@jaswrks jaswrks commented Nov 12, 2015

Next Actions (Step 1 of 2)

  • New feature branch in the websharks/zencache-pro repo.

  • After this line add two new option keys.

    'exclude_uris_client_side_too'   => '0', // `0|1` enable?
    'exclude_client_side_uris' => '', // Line-delimited list of URIs.
  • After this line add the following:

    case 'exclude_client_side_uris': // Converts to regex (caSe insensitive).
  • After this line add the following:

    if ($self->options['exclude_uris_client_side_too']) {
        $possible_advanced_cache_constant_key_values['exclude_client_side_uris'] .= "\n".$self->options['exclude_uris'];
    }
  • After this line add the following:

    if (!defined('ZENCACHE_EXCLUDE_CLIENT_SIDE_URIS')) {
        /**
         * Client-side URI exclusions.
         *
         * @since 15xxxx Adding support for client-side URI exclusions.
         *
         * @var string A regular expression; else an empty string.
         */
        define('ZENCACHE_EXCLUDE_CLIENT_SIDE_URIS', '%%ZENCACHE_EXCLUDE_CLIENT_SIDE_URIS%%');
    }
  • Replace this method with the following:

    /*
    * Sends no-cache headers (if applicable).
    *
    * @since 150422 Rewrite. Enhanced/altered 15xxxx.
    */
    $self->maybeStopBrowserCaching = function () use ($self) {
        switch ((bool) ZENCACHE_ALLOW_BROWSER_CACHE) {
    
            case true: // If global config allows, check exclusions.
    
                if (isset($_GET[strtolower(SHORT_NAME).'ABC'])) {
                    if (!filter_var($_GET[strtolower(SHORT_NAME).'ABC'], FILTER_VALIDATE_BOOLEAN)) {
                        return $self->sendNoCacheHeaders(); // Disallow.
                    } // Else, allow client-side caching; because `ABC` is a true-ish value.
                    // ↑ Note that exclusion patterns are ignored in this case, in favor of `ABC`.
                } elseif (ZENCACHE_EXCLUDE_CLIENT_SIDE_URIS && preg_match(ZENCACHE_EXCLUDE_CLIENT_SIDE_URIS, $_SERVER['REQUEST_URI'])) {
                    return $self->sendNoCacheHeaders(); // Disallow.
                }
                return; // Allow browser caching; default behavior in this mode.
    
            case false: // Global config disallows; check inclusions.
    
                if (isset($_GET[strtolower(SHORT_NAME).'ABC'])) {
                    if (filter_var($_GET[strtolower(SHORT_NAME).'ABC'], FILTER_VALIDATE_BOOLEAN)) {
                        return; // Allow, because `ABC` is a false-ish value.
                    } // Else, disallow client-side caching; because `ABC` is a true-ish value.
                    // ↑ Note that inclusion patterns are ignored in this case, in favor of `ABC`.
                }
                return $self->sendNoCacheHeaders(); // Disallow; default behavior in this mode.
        }
    };
  • After this line add the following:

    /*
    * Sends no-cache headers.
    *
    * @since 15xxxx Enhancing no-cache headers.
    */
    $self->sendNoCacheHeaders = function() use($self) {
        header_remove('Last-Modified');
        header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
        header('Cache-Control: no-cache, must-revalidate, max-age=0');
        header('Pragma: no-cache');
    };
  • Submit PR.

@jaswrks
Copy link

@jaswrks jaswrks commented Nov 12, 2015

Next Actions (Step 2 of 2 — On Deck)

  • New feature branch in the websharks/zencache-pro repo.
  • Add UI options (as described above) that allow a site owner to control:
    • exclude_uris_client_side_too
    • exclude_client_side_uris
  • Submit PR.

Note: The above instructions for Step 2 are rather vague. If you're able, attempt step 2 right away. Otherwise, once step 1 is complete hit me on Slack for a more complete set of Step 2 instructions.

@jaswrks
Copy link

@jaswrks jaswrks commented Nov 12, 2015

Assigning this to @renzms :-)

@jaswrks
Copy link

@jaswrks jaswrks commented Nov 12, 2015

@raamdev Whenever you review the PR for this issue I suggest taking a look at this one also, because it should be easy to knock that other GHI out whenever you close this one; i.e., the no-cache headers are being moved to a separate routine in this issue, so that should make it easier. See: #371

@renzms
Copy link

@renzms renzms commented Nov 18, 2015

@jaswsinc
Hi, just pushed step 1, I'll have a go at step 2 to try things on my own. If I have any trouble ,then I'll go ahead and sent you a message on slack. 👍

@jaswrks
Copy link

@jaswrks jaswrks commented Nov 19, 2015

@renzms I reviewed your work in Step 1. Looks fantastic! 💯

I'll have a go at step 2 to try things on my own. If I have any trouble ,then I'll go ahead and sent you a message on slack.

Awesomesauce! 😄

@renzms
Copy link

@renzms renzms commented Nov 21, 2015

@jaswsinc

Here's my take on step 2, submitting PR as well. The placement, style and the wording I'm sure are subject to change.

plugin options renz s test area wordpress

@jaswrks
Copy link

@jaswrks jaswrks commented Nov 23, 2015

@renzms Lookin' good!

@raamdev originally wrote...

It would be nice if there were a few extra options inside the existing URI Exclusion Patterns panel (such as an option to "Also exclude these URLs from Client-Side Caching"),

So there should be a checkbox option under the URI Exclusion patterns.

@renzms
Copy link

@renzms renzms commented Nov 25, 2015

@jaswsinc

Updated, tested and submitting PR for review. Thanks!

plugin options renz s test area wordpress 1

Options:
screen shot 2015-11-25 at 8 16 22 pm

renzms added a commit to wpsharks/comet-cache-pro that referenced this issue Nov 25, 2015
@raamdev raamdev added this to the Next Release (Pro) milestone Nov 25, 2015
@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Nov 25, 2015

@renzms Looking nice! Thank you. Here's some feedback:

  • Move these new options to the very bottom of the Client-Side Cache panel (ZenCache → Plugin Options → Client-Side Cache), as I feel it makes more sense to go there. (Having it in the URI Exclusion Patterns panel makes things confusing: two different types of URI Exclusion Patterns). Also, URI Exclusion Patterns are far more likely to be used than Client-Side Cache Exclusion patterns.
  • Change the "Excluding URIs from Client-Side Caching" header to "Client-Side Caching Exclusion Patterns" and then remove the "Don't Cache These URLs from Client-Side Caching too?" header.
  • Remove the "Don't Cache These Special URI Exclusion Patterns from Client-Side Caching Only?" header; it's not necessary.
  • Remove the option to enable/disable this feature--if there are exclusion patterns in the box, they will be used, otherwise not (the same way URI Exclusion Patterns works).
@renzms
Copy link

@renzms renzms commented Nov 26, 2015

@raamdev

Changes made! Submitting PR. Thanks for feedback. Please see screenshot below for changes:
plugin options renz s test area wordpress 2

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Nov 26, 2015

renzms added a commit to wpsharks/comet-cache-pro that referenced this issue Dec 2, 2015
@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Dec 4, 2015

Next Pro Release Changelog:

  • New Feature! Client-Side Caching now includes a new URI Exclusion Patterns for Client-Side Caching, allowing you to exclude specific URIs from being cached by a client-side browser when Client-Side Caching is enabled. Props @renzms. See Issue #498.
@raamdev raamdev closed this Dec 4, 2015
@wpsharks wpsharks locked and limited conversation to collaborators Dec 21, 2015
@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Dec 21, 2015

ZenCache Pro v151220 has been released and includes changes worked on as part of this GitHub Issue. See the release announcement for further details.


This issue will now be locked to further updates. If you have something to add related to this GitHub Issue, please open a new GitHub Issue and reference this one (#498).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants