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

Update ajax headers continously #1807

Open
JoFrMueller opened this issue Apr 27, 2020 · 3 comments · May be fixed by #1833
Open

Update ajax headers continously #1807

JoFrMueller opened this issue Apr 27, 2020 · 3 comments · May be fixed by #1833

Comments

@JoFrMueller
Copy link
Contributor

In environments where the ajaxHeaders property needs to get updated every n minutes, there's no way to invalidate existing tiles except calling TiledImage.reset() which just removes all tiles (from cache and visually) and reloads them.

This behaviour is not too nice, as it just steals away tiles from the user's field of view for some short amount of time. Authorization tokens are often refreshed in less than 1 minute which would yield many forced and visually conceived redraws.

By relying on the tiledImage.ajaxHeaders property instead of the tile.ajaxHeaders we'd be able to change ajax headers constantly while always considering the most up to date ones. What would be the counter arguments against the following approach?

function loadTile( tiledImage, tile, time ) {
    tile.loading = true;
    tiledImage._imageLoader.addJob({
        src: tile.url,
        loadWithAjax: tile.loadWithAjax,
        ajaxHeaders: tiledImage.ajaxHeaders, // Changed from tile.ajaxHeaders
        crossOriginPolicy: tiledImage.crossOriginPolicy,
        ajaxWithCredentials: tiledImage.ajaxWithCredentials,
        callback: function( image, errorMsg, tileRequest ){
            onTileLoad( tiledImage, tile, time, image, errorMsg, tileRequest );
        },
        abort: function() {
            tile.loading = false;
        }
    });
}

Also I didn't get what it's all about to include the token as part of the cache key. Does anyone know why it's done like this?

// Existing code:
if (this.ajaxHeaders) {
    this.cacheKey = this.url + "+" + JSON.stringify(this.ajaxHeaders);
} else {
    this.cacheKey = this.url;
}
// Don't consider ajax headers as part of cache keys at all.
// With this small change, caching, viewing and updating did work just fine:
this.cacheKey = this.url;

Thanks in advance for any information on the topic!

@iangilman
Copy link
Member

They both sound like good improvements to me. Probably we just didn't think about this scenario at the time.

I believe @seanich did the original Ajax headers work… Sean, any thoughts on these refinements?

@JoFrMueller would you be up for writing a patch?

@JoFrMueller
Copy link
Contributor Author

Thanks for taking the time to review.

Patch could be provided, yes.

@iangilman
Copy link
Member

Great! Please do :-)

@JoFrMueller JoFrMueller linked a pull request Jun 5, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants