Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breeze Metadata request URL with cache bust

I'm currently using Breeze.js (version 1.4.1) along with the HotTowel template, and everything is working wonderfully.

However, I was wondering if there is a way to have breeze include in the request sent to get the Metadata a configurable suffix, such as ?v=1.0.0.1, in a similar fashion to what I'm currently doing with require.js to bust the local cache during version changes.

This would provide the benefit of having users cache the metadata locally and avoid unnecessary requests for the same unchanged metadata. Even also have server-side caching and avoid the metadata generation altogether when possible.

For the actual WebApi caching I'm currently using WebApi.OutputCache so that would fit in nicely with this.

like image 873
Pablo Romeo Avatar asked Dec 13 '13 19:12

Pablo Romeo


Video Answer


2 Answers

Well, I've found one way of doing it, without any specific support from breeze, just WebApi routing.

I just basically changed the controller route to the following:

GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "BreezeApi",
            routeTemplate: "breeze/{appVersion}/{controller}/{action}"
        );

And then when creating the EntityManager, I do it as follows:

var manager = new breeze.EntityManager('breeze/' + appVersion + '/data');

Where appVersion has the incremental numeric version value.

This lets you later configure caching for the Metadata action, such as:

[HttpGet]
[CacheOutput(ClientTimeSpan = CLIENT_DURATION, ServerTimeSpan = SERVER_DURATION)]
public string Metadata()
{
    return _contextProvider.Metadata();
}

I'll leave the question open in case someone has a cleaner solution, or one implemented by breeze internally.

like image 118
Pablo Romeo Avatar answered Sep 20 '22 12:09

Pablo Romeo


You might look at the Breeze documentation topic "Load metadata from script" which describes capturing metadata in a JavaScript file and loading it in your index.html next to other script. You could apply standard cache-busting techniques to such metadata.js and even distribute from a CDN if that floats your boat.

like image 44
Ward Avatar answered Sep 18 '22 12:09

Ward