Skip to content

Commit

Permalink
Fix caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath committed Jun 24, 2015
1 parent f6172db commit 9dff37c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/sodb.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports =
args = Array.prototype.slice.call(arguments)
search = args.map(@expandQuery)

@cache.hit hash.sha1(search), @objectHash, => @findResults(search)
@cache.hit hash.sha1(search), @dbRevision, => @findResults(search)

findResults: (search) ->
results = @objects
Expand Down
24 changes: 23 additions & 1 deletion tests/sodb-tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ if /lib-cov/.test(__dirname)
else
sodb = require path.join(__dirname, '..')

cacheValue = true

for caching in [true, false]
describe "sodb with caching #{caching}", ->
[db] = []

before ->
db = new sodb({cache: caching})
db = new sodb({cache: cacheValue})

after ->
cacheValue = false

it 'should have no entires in a new db', ->
expect(db.objects.length).to.equal 0

it 'should have the cache set', ->
expect(db.options.cache).to.equal cacheValue

if caching
it 'should have a dbrevision of 0', ->
expect(db.dbRevision).to.equal 0

describe 'adding records', ->
it 'should add an id property', ->
db.add({name: 'david', age: 10, eyes: 1})
Expand Down Expand Up @@ -73,8 +85,14 @@ for caching in [true, false]
results = db.where({name: 'dave'})
expect(results.length).to.equal 0

if cacheValue
dbrev = db.dbRevision

db.update(entry)

if cacheValue
expect(db.dbRevision).to.equal dbrev + 1

results = db.where({name: 'dave'})
expect(results.length).to.equal 1

Expand All @@ -93,3 +111,7 @@ for caching in [true, false]
expect(results.length).to.equal 0
expect(db.objects.length).to.equal 4
expect(db.count()).to.equal 3

if caching
it 'should have a dbrevision of not 0', ->
expect(db.dbRevision).not.to.equal 0

0 comments on commit 9dff37c

Please sign in to comment.