mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Invalidate cache when it is rejected by v8
This commit is contained in:
@@ -48,3 +48,22 @@ describe "FileSystemCacheBlobStorage", ->
|
||||
expect(cacheBlobStorage.get("foo")).toEqual(new Buffer("foo"))
|
||||
expect(cacheBlobStorage.get("bar")).toEqual(new Buffer("changed"))
|
||||
expect(cacheBlobStorage.get("qux")).toEqual(new Buffer("qux"))
|
||||
|
||||
it "allows to delete keys from both memory and stored buffers", ->
|
||||
cacheBlobStorage.set("a", new Buffer("a"))
|
||||
cacheBlobStorage.set("b", new Buffer("b"))
|
||||
cacheBlobStorage.save()
|
||||
|
||||
cacheBlobStorage = FileSystemCacheBlobStorage.load(storageDirectory)
|
||||
|
||||
cacheBlobStorage.set("b", new Buffer("b"))
|
||||
cacheBlobStorage.set("c", new Buffer("c"))
|
||||
cacheBlobStorage.delete("b")
|
||||
cacheBlobStorage.delete("c")
|
||||
cacheBlobStorage.save()
|
||||
|
||||
cacheBlobStorage = FileSystemCacheBlobStorage.load(storageDirectory)
|
||||
|
||||
expect(cacheBlobStorage.get("a")).toEqual(new Buffer("a"))
|
||||
expect(cacheBlobStorage.get("b")).toBeUndefined()
|
||||
expect(cacheBlobStorage.get("c")).toBeUndefined()
|
||||
|
||||
1
spec/fixtures/native-cache/file-3.js
vendored
Normal file
1
spec/fixtures/native-cache/file-3.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = function () { return 3; }
|
||||
@@ -4,7 +4,7 @@ describe "NativeCompileCache", ->
|
||||
|
||||
beforeEach ->
|
||||
cachedFiles = []
|
||||
fakeCacheStorage = jasmine.createSpyObj("cache storage", ["set", "get", "has"])
|
||||
fakeCacheStorage = jasmine.createSpyObj("cache storage", ["set", "get", "has", "delete"])
|
||||
nativeCompileCache.setCacheStorage(fakeCacheStorage)
|
||||
nativeCompileCache.install()
|
||||
|
||||
@@ -36,3 +36,12 @@ describe "NativeCompileCache", ->
|
||||
|
||||
expect(fakeCacheStorage.set).not.toHaveBeenCalled()
|
||||
expect(fn1()).toBe(1)
|
||||
|
||||
it "deletes previously cached code when the cache is not valid", ->
|
||||
fakeCacheStorage.has.andReturn(true)
|
||||
fakeCacheStorage.get.andCallFake -> new Buffer("an invalid cache")
|
||||
|
||||
fn3 = require('./fixtures/native-cache/file-3')
|
||||
|
||||
expect(fakeCacheStorage.delete).toHaveBeenCalledWith(require.resolve('./fixtures/native-cache/file-3'))
|
||||
expect(fn3()).toBe(3)
|
||||
|
||||
@@ -47,6 +47,11 @@ module.exports = (function () {
|
||||
return this.inMemoryCache.set(key, buffer)
|
||||
}
|
||||
|
||||
FileSystemCacheBlobStorage.prototype.delete = function (key) {
|
||||
this.inMemoryCache.delete(key)
|
||||
delete this.storedCacheMap[key]
|
||||
}
|
||||
|
||||
FileSystemCacheBlobStorage.prototype.getFromMemory = function (key) {
|
||||
return this.inMemoryCache.get(key)
|
||||
}
|
||||
|
||||
@@ -56,12 +56,16 @@ NativeCompileCache = (function () {
|
||||
var wrapper = Module.wrap(content)
|
||||
|
||||
var compiledWrapper = null
|
||||
var compilationResult = null
|
||||
if (cacheStorage.has(filename)) {
|
||||
var buffer = cacheStorage.get(filename)
|
||||
compiledWrapper =
|
||||
cachedVm.runInThisContextCached(wrapper, filename, buffer).result
|
||||
compilationResult = cachedVm.runInThisContextCached(wrapper, filename, buffer)
|
||||
compiledWrapper = compilationResult.result
|
||||
if (compilationResult.wasRejected) {
|
||||
cacheStorage.delete(filename)
|
||||
}
|
||||
} else {
|
||||
var compilationResult = cachedVm.runInThisContext(wrapper, filename)
|
||||
compilationResult = cachedVm.runInThisContext(wrapper, filename)
|
||||
if (compilationResult.cacheBuffer) {
|
||||
cacheStorage.set(filename, compilationResult.cacheBuffer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user