-
-
Notifications
You must be signed in to change notification settings - Fork 179
refactor: replace cacache with flat-cache #121
Conversation
@evilebottnawi @michael-ciniawsky - As soon as we land #108, this one is up next to be included in the initial 1.0.0 release. The @angular/cli group needs this for a perf issue. |
@d3viant0ne I'll need to update this to work on top of #108. |
@michael-ciniawsky - The snapshots in #108 need to be updated before that merges. Outside of that, i'm pretty sure it's ready to go. RE License change: That gets messy & has lingering legal issues not to mention we would probably have to engage the JSF legal team which I would rather avoid. We shouldn't be using CC0 libs either for pretty much the same reason as Angular. |
#108 landed 🎉 |
Are there any alternatives available ? |
@filipesilva please rebase |
@michael-ciniawsky there's a couple of alternatives, I just searched for @evilebottnawi done. |
I'm looking at the snapshots and there seems to be a problem, still fixing. |
Seems good now 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we wait until the relicensing is done ?
Do we have any basic benchmark data comparing flat-cache
to cacache
? I'm worried about flat-cache
using sync
File I/O
src/uglify/cache.js
Outdated
|
||
const cacheId = 'uglifyjs-webpack-plugin'; | ||
|
||
export default class Cache { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a class here ?
const cache = {
get (dir, key) {},
put (dir, key, data) {},
list (dir) {},
clear (dir) {}
}
export default cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't necessarily need a class, no. Something with a similar api was needed for the Jest spies but that's it. I'll change it to an object if it's preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bear in mind that changing it from Cache
to cache
necessitated a few other renames to prevent shadowed variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loading the ?whole cache flatCache.load(id, dir)
on every method call seems odd or I'm missing something ?
src/uglify/index.js
Outdated
import findCacheDir from 'find-cache-dir'; | ||
import workerFarm from 'worker-farm'; | ||
import minify from './minify'; | ||
import Cache from './cache'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cache
=> cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/uglify/cache.js
Outdated
@@ -0,0 +1,23 @@ | |||
import flatCache from 'flat-cache'; | |||
|
|||
const cacheId = 'uglifyjs-webpack-plugin'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cacheId
=> id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
const id = 'uglifyjs-webpack-plugin'; | ||
|
||
const cache = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export default class Cache {
constructor (dir) {
this.id = 'uglifyjs-webpack-plugin'
this.cache = flatCache.load(this.id, dir)
}
get (key) {
return this.cache.getKey(key)
},
put (key, data) {
this.cache.setKey(key, JSON.stringify(data))
this.cache.save(true)
},
list () {
return this.cache.all()
},
clear (dir) {
flatCache.clearAll(dir)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative
// cache(dir)
export default function (dir) {
const id = 'uglifyjs-webpack-plugin'
const cache = flatCache.load(id, dir)
return {
get (key) {
return cache.getKey(key)
},
put (key, data) {
cache.setKey(key, JSON.stringify(data))
cache.save(true)
},
list () {
return cache.all()
},
clear (dir) {
flatCache.clearAll(dir)
}
}
}
import findCacheDir from 'find-cache-dir'; | ||
import workerFarm from 'worker-farm'; | ||
import minify from './minify'; | ||
import cache from './cache'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache
=> Cache
const { cache, parallel } = options; | ||
this.cacheDir = cache === true ? findCacheDir({ name: 'uglifyjs-webpack-plugin' }) : cache; | ||
const { cache: useCache, parallel } = options; | ||
this.cacheDir = useCache === true ? findCacheDir({ name: 'uglifyjs-webpack-plugin' }) : useCache; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.cacheDir = cache === true ? findCacheDir({ name: 'uglifyjs-webpack-plugin' }) : cache;
this.cache = new Cache(this.cacheDir);
@@ -58,15 +58,21 @@ export default class { | |||
const done = () => step(index, result); | |||
|
|||
if (this.cacheDir && !result.error) { | |||
cacache.put(this.cacheDir, task.cacheKey, JSON.stringify(data)).then(done, done); | |||
cache.put(this.cacheDir, task.cacheKey, JSON.stringify(data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.cache.put(task.cacheKey, JSON.stringify(data))
@michael-ciniawsky the approach that you're suggesting (using a instanced class) will not work with the tests as they exist currently, since they rely on being able to spy on static cache methods. It would also require the cache being exposed cache instance being exposed so the tests could tap into it. Is this something you want changed? |
@michael-ciniawsky the process of relicensing cacache would likely take weeks, and we've (Angular CLI's team) been waiting since July for this release to have a proper license. The current adaptor would allow us to change back to cacache when they do support an open source license, without any changes to the code. |
FYI - In it's current state this throws when trying to access cached build assets. |
@d3viant0ne did you pull the new changes? I tried a rebuild some 10m ago and rebuilds were good. I amended the previous commit with the fix some 20m ago. |
Heads-up: I'm working on relicensing cacache, if it makes any difference here. Should be ready soonish, since folks are 👍 pretty quick and there aren't a lot of contributors rn. Edit: I took a look at flat-cache and I suggest y'all find something different. I don't think that library's gonna hold up at all under concurrency conditions. The most likely scenario is you'll have an eternally-invalidated cache, since you're going to have a race that looks like:
meaning: "foo": 1
"bar": 2
} // end of worker 2, chunk 2
"a": 1, // worker 1, chunk 1
"b": 2,
"c": 3
} // end of worker 1, chunk 1 And as soon as |
@hansl fwiw, no one told me about this until a couple of days ago, and I needed an excuse to start the relicense process, since it needed to happen anyway. |
Fixed by #145 |
Heya @zkat, I just wanted to thank you for being so speedy in relicensing You're analysis of |
Yep, thanks again @zkat for all the (quick) help here 👍 |
See #120 for reasoning
Issues