Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Make caching a little smarter. #35

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

masegraye
Copy link

CommonJS dictates that if a module has been required in the past, its exports should be cached and returned the next time require is called for that module in the same runtime.

Currently, Stitch does not return cached modules if they're only found after adding "/index" to the require name.

Example module structure:

mf/
    index.coffee
    events.coffee

If I call:

require("mf/events");
require("mf/events");

the contents of mf/events.coffee will only be executed once, as expected. However, if I call:

require("mf");
require("mf");

the contents of mf/index.coffee will be executed twice. This fixes that.

Mason Browne added 2 commits February 29, 2012 20:11
… name, try using it if the default name doesn't resolve in cache rather than re-executing the module function.
@sstephenson
Copy link
Owner

Fantastic. Could you add a test case for this too?

@masegraye
Copy link
Author

Word.

@masegraye
Copy link
Author

Done, by the by. :)

@masegraye
Copy link
Author

Bump.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants