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

Cache-style middleware not working #57

Closed
rblstr opened this issue May 31, 2016 · 0 comments
Closed

Cache-style middleware not working #57

rblstr opened this issue May 31, 2016 · 0 comments

Comments

@rblstr
Copy link
Contributor

rblstr commented May 31, 2016

Following the https://github.com/englercj/resource-loader/blob/master/src/middlewares/caching/memory.js middleware example, the following code should populate resource.data and not perform a network request. However, calling resource.complete() doesn't seem to stop the load from happening.

var Loader = require ('resource-loader');

var loader = new Loader();

var cache = {
    'example.json': {
        'test': 'one, two'
    }
};

loader
    .add('example.json')
    .before(function (resource, next) {
        if (cache[resource.url] != null) {
            resource.data = cache[resource.url];
            resource.complete();
        }

        console.log('calling next');
        next();
    })
    .load(function (loader, resources) {
        console.log('complete');
    });

I would expect this to simply call the complete callback with the cached data in the response.data, however it still tries to perform the web request.

Is the example code out of date? Or is it no longer possible to complete loads in the before middleware? I can't see anything in the code to check if the resource load was completed before making the load request.

englercj added a commit that referenced this issue Jul 27, 2016
Fix #57 - Proper handling of 'before' middleware
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

1 participant