Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top