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

Persistent caches #282

Open
joliss opened this issue Oct 15, 2015 · 3 comments
Open

Persistent caches #282

joliss opened this issue Oct 15, 2015 · 3 comments

Comments

@joliss
Copy link
Member

joliss commented Oct 15, 2015

Talking with @stefanpenner, here's an idea of how to do it:

In a plugin that wants persistent caches, call the base constructor:

Plugin.call(this, ..., { persistentCache: __dirname })

Broccoli will scan the source files of the calling plugin and its npm dependencies and hash over their mtimes using hash-for-dep. (We cannot just hash over version numbers, because people might be editing some of the sources.)

Multiple instances (nodes) of the same plugin share the same cache space.

During the build the plugin gets and sets keys:

this.persistentCache.getAndRetain(computeHash([relPath, mtime, otherOptions])) // => buffer or null
this.persistentCache.setAndRetain(computeHash([relPath, mtime, otherOptions]), buffer)

Broccoli implicitly adds the hash-for-dep hash to the key.

At the end of each build, all the keys in the cache that haven't been retained by a "get" or "set" call are evicted from the cache.

Different environments (dev, test, production) might use slightly different sets of nodes. We don't want them to evict each other. So we scope on the environment so they're independent.

/tmp/broccoli-persistent-cache-HOSTNAME-_home_jo_myproject/dev/deadbeef
     ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
     fixed                     allow    project path       env key hash
                               for NFS  (likely hashed
                                        to deal with long 
                                        paths)

Multiple processes can use the same persistent cache at the same time. We need to be a bit careful that concurrent setting or eviction doesn't break things.

@rwjblue
Copy link
Member

rwjblue commented Oct 15, 2015

👍

@BryanCrotaz
Copy link

I'm writing a broccoli plugin - what is best practice for caching files?

@mariokostelac
Copy link

mariokostelac commented Jul 8, 2016

It would worth a shot to think abstracting mtime to fileVersion, calculated by a passed function, defaulted to getting mtime (or not). That would allow reusing persisted cache on repositories based on version controls that do not preserve file metadata (like git, for example).

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

4 participants