Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upOption to store buffer data #5
Conversation
This comment has been minimized.
This comment has been minimized.
Need to rebase against master. Also you should probably update the README explaining this new option. |
This comment has been minimized.
This comment has been minimized.
Ping @avitale. This PR is out of date and we haven't heard anything from you in quite a while. |
} | ||
catch (err) { | ||
return callback(err); | ||
if(this.settings.buffer){ |
This comment has been minimized.
This comment has been minimized.
if(this.settings.buffer){ | ||
if (Buffer.isBuffer(value)) { | ||
stringifiedValue = value; | ||
} else { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hi @arb, if you are interested in merging this pull request I can look into it again |
This comment has been minimized.
This comment has been minimized.
@avitale yes, please resolve the merge conflicts. |
} | ||
catch (err) { | ||
return callback(new Error('Bad value content')); | ||
if(this.settings.buffer){ |
This comment has been minimized.
This comment has been minimized.
return callback(new Error('Bad value content')); | ||
if(this.settings.buffer){ | ||
value = envelope.item; | ||
} else { |
This comment has been minimized.
This comment has been minimized.
@@ -10,4 +10,4 @@ Memory adapter for catbox | |||
cached. Once this limit is reached no additional items will be added to the cache | |||
until some expire. The utilized memory calculation is a rough approximation and must | |||
not be relied on. Defaults to `104857600` (100MB). | |||
|
|||
- `buffer` - store Buffer data, values are not stringified and parsed. Defaults to `false`. |
This comment has been minimized.
This comment has been minimized.
cjihrig
Sep 5, 2014
Contributor
Could you add a sentence mentioning that storing a Buffer
means that the contents could change while in cache.
@@ -73,6 +73,42 @@ describe('Memory', function () { | |||
}); | |||
}); | |||
|
|||
it('gets a buffer item after setting it', function (done) { | |||
|
|||
var buffer = new Buffer("I'm a string!", "utf-8"); |
This comment has been minimized.
This comment has been minimized.
|
||
var buffer = new Buffer("I'm a string!", "utf-8"); | ||
|
||
var client = new Catbox.Client(new Memory({buffer: true})); |
This comment has been minimized.
This comment has been minimized.
cjihrig
Sep 5, 2014
Contributor
No blank line before this. Add a blank line after. Add a space after {
and before }
var client = new Catbox.Client(new Memory({buffer: true})); | ||
client.start(function (err) { | ||
|
||
var key = { id: 'x', segment: 'test' }; |
This comment has been minimized.
This comment has been minimized.
|
||
it('fails setting a non buffer when expecting a buffer', function (done) { | ||
|
||
var client = new Catbox.Client(new Memory({buffer: true})); |
This comment has been minimized.
This comment has been minimized.
var client = new Catbox.Client(new Memory({buffer: true})); | ||
client.start(function (err) { | ||
|
||
var key = { id: 'x', segment: 'test' }; |
This comment has been minimized.
This comment has been minimized.
client.start(function (err) { | ||
|
||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, "I'm a string!", 500, function (err) { |
This comment has been minimized.
This comment has been minimized.
|
||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, "I'm a string!", 500, function (err) { | ||
expect(err.message).to.equal('Value is not a Buffer'); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This is good, but I think it would be better to support a mix of Buffers and stringified objects. |
This comment has been minimized.
This comment has been minimized.
Supporting a mix would be great. I am wondering if we can do it in catbox-memory or catbox API has to be changed as well. Any opinion about it? |
This comment has been minimized.
This comment has been minimized.
I was thinking you could add a flag |
This comment has been minimized.
This comment has been minimized.
I have improved the code, now it supports mixed content. I haven't yet added the |
This comment has been minimized.
This comment has been minimized.
Yes, it can when you store a |
This comment has been minimized.
This comment has been minimized.
Thanks for the useful comments, I have added the |
avitale commentedJun 17, 2014
This pull request adds the option to store buffer data in catbox-memory.
With this option catbox-memory can be used to store pre-compressed data (ex gzip).