Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed May 29, 2019
1 parent 9bd81b1 commit 194d3fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 35 deletions.
24 changes: 8 additions & 16 deletions entity-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports.defaults = {
maxhot: 1111,
maxage: 22222,
expires: 3600, // 1 Hour
hot: true, // hot cache active
hot: true // hot cache active
}

function entity_cache(options) {
Expand All @@ -19,10 +19,12 @@ function entity_cache(options) {

// NOTE: never used for versionKeys - these must always sync against
// remote cache
var hotcache = options.hot && new LRUCache({
max: options.maxhot,
maxAge: options.maxage // always expire ents - weak eventual consistency
})
var hotcache =
options.hot &&
new LRUCache({
max: options.maxhot,
maxAge: options.maxage // always expire ents - weak eventual consistency
})

// Statistics

Expand All @@ -47,7 +49,6 @@ function entity_cache(options) {
.add('plugin:entity-cache,list:hot-keys', list_hot_keys)
.add('plugin:entity-cache,clear:hot-keys', clear_hot_keys)


// Cache write

var writeKey = function(seneca, vkey, reply) {
Expand Down Expand Up @@ -369,7 +370,6 @@ function entity_cache(options) {
return { name: 'entity-cache' }
}


const intern = (entity_cache.intern = {
make_version_key: function(ent, id, prefix) {
// Example: 'SE~v~zen/moon/bar~171qa9'
Expand All @@ -381,15 +381,7 @@ const intern = (entity_cache.intern = {
make_data_key: function(ent, id, version, prefix) {
// Example: 'SE~d~0~zen/moon/bar~171qa9'

var key =
prefix +
'~d~' +
version +
'~' +
ent.entity$ +
'~' +
id
var key = prefix + '~d~' + version + '~' + ent.entity$ + '~' + id
return key
}

})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seneca/entity-cache",
"version": "0.1.1",
"version": "0.2.0",
"description": "Versioned caching plugin for seneca",
"main": "entity-cache.js",
"scripts": {
Expand Down
24 changes: 6 additions & 18 deletions test/entity-cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ var it = make_it(lab)
var expect = Code.expect

lab.it('does not damage entities placed into LRUCache', async function() {
var seneca = await seneca_instance()
.ready()
var seneca = await seneca_instance().ready()

var id = seneca.util.Nid()

Expand Down Expand Up @@ -91,29 +90,23 @@ lab.it('does not damage entities placed into LRUCache', async function() {
var qaz0c = await seneca.entity('qaz').load$(id)
expect(qaz0c.data$(false)).equals({ id: id, a: 1, b: 2, e: 5 })


var memdata = await seneca.post('role:mem-store,cmd:dump')
var qaz1md = {...memdata[void 0].qaz[id]}
var qaz1md = { ...memdata[void 0].qaz[id] }
qaz1md.id = seneca.util.Nid()
qaz1md.a = 2
memdata[void 0].qaz[qaz1md.id] = qaz1md


//memdata = await seneca.post('role:mem-store,cmd:dump')
//console.dir(memdata,{depth:null})

var qaz1 = await seneca.entity('qaz').load$(qaz1md.id)
expect(qaz1.data$(false)).equals({ id: qaz1md.id, a: 2, b: 2, e: 5 })

hot_keys = await seneca.post('plugin:entity-cache,list:hot-keys')

expect(hot_keys).equal({
keys: [
'SE~d~1~-/-/qaz~'+qaz1md.id,
'SE~d~2~-/-/qaz~'+id
]
keys: ['SE~d~1~-/-/qaz~' + qaz1md.id, 'SE~d~2~-/-/qaz~' + id]
})

})

it('writes then reads a record', function(done) {
Expand Down Expand Up @@ -209,9 +202,8 @@ it('writes then reads a record', function(done) {
})
})


it('writes then reads a record with no hotcache', function(done) {
var seneca = seneca_instance({hot: false})
var seneca = seneca_instance({ hot: false })

seneca.ready(function() {
var type = internals.type()
Expand Down Expand Up @@ -303,7 +295,6 @@ it('writes then reads a record with no hotcache', function(done) {
})
})


it('updates a record', function(done) {
var seneca = seneca_instance()

Expand Down Expand Up @@ -814,10 +805,7 @@ describe('load()', function() {
// Drop from upstream cache

seneca.act(
'role:cache, cmd:delete, key:SE~d~1~-/-/' +
type +
'~' +
saved1.id,
'role:cache, cmd:delete, key:SE~d~1~-/-/' + type + '~' + saved1.id,
function(err, result) {
expect(result).to.exist()
expect(err).to.not.exist()
Expand Down

0 comments on commit 194d3fd

Please sign in to comment.