Commit fef31883d6fac00464b93173ece82d343f896256

Authored by Arek W
1 parent 98385496

Disable cache by default. Closes #672

Changelog.md
  1 +### v2.2.0
  2 +- Singleton/cache disabled by default (#672)
  3 +
1 ### v2.1.27 4 ### v2.1.27
2 - Fix noisy mysql debug output (#642) 5 - Fix noisy mysql debug output (#642)
3 6
Readme.md
@@ -70,7 +70,7 @@ orm.connect("mysql://username:password@host/database", function (err, db) { @@ -70,7 +70,7 @@ orm.connect("mysql://username:password@host/database", function (err, db) {
70 }); 70 });
71 71
72 // add the table to the database 72 // add the table to the database
73 - db.sync(function(err) { 73 + db.sync(function(err) {
74 if (err) throw err; 74 if (err) throw err;
75 75
76 // add a row to the person table 76 // add a row to the person table
@@ -90,7 +90,7 @@ orm.connect("mysql://username:password@host/database", function (err, db) { @@ -90,7 +90,7 @@ orm.connect("mysql://username:password@host/database", function (err, db) {
90 // err.msg = "under-age"; 90 // err.msg = "under-age";
91 }); 91 });
92 }); 92 });
93 - 93 +
94 }); 94 });
95 }); 95 });
96 }); 96 });
@@ -278,7 +278,7 @@ var Person = db.define("person", { @@ -278,7 +278,7 @@ var Person = db.define("person", {
278 278
279 Other options: 279 Other options:
280 280
281 -- `cache` : (default: `true`) Set it to `false` to disable Instance cache ([Singletons](#singleton)) or set a timeout value (in seconds); 281 +- `cache` : (default: `false`) Set it to `true` to enable Instance cache ([Singletons](#singleton)) or set a timeout value (in seconds);
282 - `autoSave` : (default: `false`) Set it to `true` to save an Instance right after changing any property; 282 - `autoSave` : (default: `false`) Set it to `true` to save an Instance right after changing any property;
283 - `autoFetch` : (default: `false`) Set it to `true` to fetch associations when fetching an instance from the database; 283 - `autoFetch` : (default: `false`) Set it to `true` to fetch associations when fetching an instance from the database;
284 - `autoFetchLimit` : (default: `1`) If `autoFetch` is enabled this defines how many hoops (associations of associations) 284 - `autoFetchLimit` : (default: `1`) If `autoFetch` is enabled this defines how many hoops (associations of associations)
@@ -516,16 +516,16 @@ db.driver.execQuery( @@ -516,16 +516,16 @@ db.driver.execQuery(
516 516
517 ### Caching & Integrity 517 ### Caching & Integrity
518 518
519 -Model instances are cached. If multiple different queries will result in the same result, you will 519 +Model instances can be cached (turned off by default). If enabled, multiple different queries will result in the same result - you will
520 get the same object. If you have other systems that can change your database (or you're developing and need 520 get the same object. If you have other systems that can change your database (or you're developing and need
521 -to make some manual changes) you should remove this feature by disabling cache. This can be done when you're  
522 -defining the Model. 521 +to make some manual changes) you shouldn't use this feature.
  522 +It can be enabled/disabled per model:
523 523
524 ```js 524 ```js
525 var Person = db.define('person', { 525 var Person = db.define('person', {
526 name : String 526 name : String
527 }, { 527 }, {
528 - cache : false 528 + cache : true
529 }); 529 });
530 ``` 530 ```
531 531
@@ -533,7 +533,7 @@ and also globally: @@ -533,7 +533,7 @@ and also globally:
533 533
534 ```js 534 ```js
535 orm.connect('...', function(err, db) { 535 orm.connect('...', function(err, db) {
536 - db.settings.set('instance.cache', false); 536 + db.settings.set('instance.cache', true);
537 }); 537 });
538 ``` 538 ```
539 539
lib/Settings.js
@@ -6,7 +6,7 @@ var default_settings = { @@ -6,7 +6,7 @@ var default_settings = {
6 required : false 6 required : false
7 }, 7 },
8 instance : { 8 instance : {
9 - cache : true, 9 + cache : false,
10 cacheSaveCheck : true, 10 cacheSaveCheck : true,
11 autoSave : false, 11 autoSave : false,
12 autoFetch : false, 12 autoFetch : false,
package.json
@@ -43,9 +43,9 @@ @@ -43,9 +43,9 @@
43 "lodash" : "2.4.1" 43 "lodash" : "2.4.1"
44 }, 44 },
45 "devDependencies": { 45 "devDependencies": {
46 - "mysql" : "2.5.5",  
47 - "pg" : "4.3.0",  
48 - "sqlite3" : "3.0.5", 46 + "mysql" : "2.9.0",
  47 + "pg" : "4.4.3",
  48 + "sqlite3" : "3.1.0",
49 "async" : "0.9.0", 49 "async" : "0.9.0",
50 "mocha" : "1.13.0", 50 "mocha" : "1.13.0",
51 "should" : "1.2.2", 51 "should" : "1.2.2",
test/integration/association-hasone-reverse.js
@@ -153,7 +153,11 @@ describe("hasOne", function () { @@ -153,7 +153,11 @@ describe("hasOne", function () {
153 153
154 it("should be able to set an array of people as the owner", function (done) { 154 it("should be able to set an array of people as the owner", function (done) {
155 Person.find({ name: ["John Doe", "Jane Doe"] }, function (err, owners) { 155 Person.find({ name: ["John Doe", "Jane Doe"] }, function (err, owners) {
  156 + should.not.exist(err);
  157 +
156 Pet.find({ name: "Fido" }).first(function (err, Fido) { 158 Pet.find({ name: "Fido" }).first(function (err, Fido) {
  159 + should.not.exist(err);
  160 +
157 Fido.hasOwners(function (err, has_owner) { 161 Fido.hasOwners(function (err, has_owner) {
158 should.not.exist(err); 162 should.not.exist(err);
159 has_owner.should.be.false; 163 has_owner.should.be.false;
@@ -166,7 +170,10 @@ describe("hasOne", function () { @@ -166,7 +170,10 @@ describe("hasOne", function () {
166 should(Array.isArray(owners)); 170 should(Array.isArray(owners));
167 owners.length.should.equal(2); 171 owners.length.should.equal(2);
168 172
169 - if (owners[0] == ownersCopy[0]) { 173 + // Don't know which order they'll be in.
  174 + var idProp = common.protocol() == 'mongodb' ? '_id' : 'id'
  175 +
  176 + if (owners[0][idProp] == ownersCopy[0][idProp]) {
170 owners[0].should.eql(ownersCopy[0]); 177 owners[0].should.eql(ownersCopy[0]);
171 owners[1].should.eql(ownersCopy[1]); 178 owners[1].should.eql(ownersCopy[1]);
172 } else { 179 } else {
test/mocha.opts
1 --reporter spec 1 --reporter spec
  2 +--timeout 5000