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

Bug when cache is set to false and cacheKey omitted in the options #30

Closed
softwarespot opened this issue Jul 15, 2015 · 2 comments
Closed

Comments

@softwarespot
Copy link
Contributor

The fix is pretty trivial with a regex in genCacheKey(). The issue is because the timestamp is tacked on afterwards, so isn't present in the url the first time around.

    var genCacheKey = function (options) {
        var url = options.url.replace(/jQuery.*/, '');

        // Strip _={timestamp}, if cache is set to false
        if (options.cache === false) {
            url = url.replace(/\??_=\d{13}/, '');
        }

        return options.cacheKey || url + options.type + (options.data || '');
    };
@SaneMethod
Copy link
Owner

Good catch, although I have to admit to some curiosity as to what circumstances might lead a developer to disable browser-level caching, but enable caching in local storage.

In any case, it looks like your proposed regex is a bit too specific - it assumes the _ parameter that jQuery appends will appear as the first parameter, which is not necessarily the case. Let's instead use the same regex that jQuery uses to detect the presence of the _ param:

/([?&])_=[^&]*/

If you'd like to make a pull request with the relevant change, I'll review and merge it.

SaneMethod added a commit that referenced this issue Jul 20, 2015
@softwarespot
Copy link
Contributor Author

Thanks for the regex tip. I managed to locate it in ajax.js for those wondering where you found it. The capture group isn't not really needed, but I guess we should be consistent with jQuery's version.

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

2 participants