Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add docs for saveInterval

  • Loading branch information...
commit df4e936f6079d645d97d93d4dd0e274e8f6543d5 1 parent 42c3a29
Francis Chong authored

Showing 1 changed file with 31 additions and 1 deletion. Show diff stats Hide diff stats

  1. +31 1 README.md
32 README.md
Source Rendered
@@ -38,7 +38,7 @@ end
38 38
39 39 Now, you can use NanoStore in your app.
40 40
41   -## Usage
  41 +## Basic Usage
42 42
43 43 ### Set default storeage type
44 44
@@ -92,3 +92,33 @@ user = User.find(:name, NSFEqualTo, "Bob").first
92 92 user.delete
93 93 ````
94 94
  95 +## Performance Tips
  96 +
  97 +NanoStore by defaults saves every object to disk one by one. To speed up inserts and edited objects, increase NSFNanoStore's ```saveInterval``` property.
  98 +
  99 +### Example
  100 +
  101 + # Create a store
  102 + store = NanoStore.shared_store = NanoStore.store
  103 +
  104 + # Increase the save interval
  105 + store.saveInterval = 1000
  106 +
  107 + # Do a bunch of inserts and/or edits
  108 + obj1 = Animal.new
  109 + obj1.name = "Cat"
  110 + store << obj1
  111 +
  112 + obj2 = Animal.new
  113 + obj2.name = "Dog"
  114 + store << obj2
  115 +
  116 + # Don't forget that some objects could be lingering in memory. Force a save.
  117 + store.save
  118 +
  119 +Note: If you set the saveInterval value to anything other one, keep in mind that some objects may still be left unsaved after being added or modified. To make sure they're saved properly, call:
  120 +
  121 + store.save
  122 +
  123 +Choosing a good saveInterval value is more art than science. While testing NanoStore using a medium-sized dictionary (iTunes MP3 dictionary) setting saveInterval to 1000 resulted in the best performance. You may want to test with different numbers and fine-tune it for your data set.
  124 +

0 comments on commit df4e936

Please sign in to comment.
Something went wrong with that request. Please try again.