Commit fef31883d6fac00464b93173ece82d343f896256
1 parent
98385496
Disable cache by default. Closes #672
Showing
6 changed files
with
24 additions
and
13 deletions
Changelog.md
Readme.md
... | ... | @@ -70,7 +70,7 @@ orm.connect("mysql://username:password@host/database", function (err, db) { |
70 | 70 | }); |
71 | 71 | |
72 | 72 | // add the table to the database |
73 | - db.sync(function(err) { | |
73 | + db.sync(function(err) { | |
74 | 74 | if (err) throw err; |
75 | 75 | |
76 | 76 | // add a row to the person table |
... | ... | @@ -90,7 +90,7 @@ orm.connect("mysql://username:password@host/database", function (err, db) { |
90 | 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 | 278 | |
279 | 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 | 282 | - `autoSave` : (default: `false`) Set it to `true` to save an Instance right after changing any property; |
283 | 283 | - `autoFetch` : (default: `false`) Set it to `true` to fetch associations when fetching an instance from the database; |
284 | 284 | - `autoFetchLimit` : (default: `1`) If `autoFetch` is enabled this defines how many hoops (associations of associations) |
... | ... | @@ -516,16 +516,16 @@ db.driver.execQuery( |
516 | 516 | |
517 | 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 | 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 | 524 | ```js |
525 | 525 | var Person = db.define('person', { |
526 | 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 | 533 | |
534 | 534 | ```js |
535 | 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
package.json
... | ... | @@ -43,9 +43,9 @@ |
43 | 43 | "lodash" : "2.4.1" |
44 | 44 | }, |
45 | 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 | 49 | "async" : "0.9.0", |
50 | 50 | "mocha" : "1.13.0", |
51 | 51 | "should" : "1.2.2", | ... | ... |
test/integration/association-hasone-reverse.js
... | ... | @@ -153,7 +153,11 @@ describe("hasOne", function () { |
153 | 153 | |
154 | 154 | it("should be able to set an array of people as the owner", function (done) { |
155 | 155 | Person.find({ name: ["John Doe", "Jane Doe"] }, function (err, owners) { |
156 | + should.not.exist(err); | |
157 | + | |
156 | 158 | Pet.find({ name: "Fido" }).first(function (err, Fido) { |
159 | + should.not.exist(err); | |
160 | + | |
157 | 161 | Fido.hasOwners(function (err, has_owner) { |
158 | 162 | should.not.exist(err); |
159 | 163 | has_owner.should.be.false; |
... | ... | @@ -166,7 +170,10 @@ describe("hasOne", function () { |
166 | 170 | should(Array.isArray(owners)); |
167 | 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 | 177 | owners[0].should.eql(ownersCopy[0]); |
171 | 178 | owners[1].should.eql(ownersCopy[1]); |
172 | 179 | } else { | ... | ... |
test/mocha.opts