From: Joel VanderWerf Date: 2008-04-02T03:11:25+09:00 Subject: Re: should I use a database or a flat file? James Dinkel wrote: > I need to store some information with my ruby program and I am not sure > on what would be the best method. I'm mostly concerned about what would > be the most efficient use of cpu resources. One option is FSDB[1] (file-system database), with one file per "category", and each file stored as YAML. This scales as well as your file system scales, is always human-readable, and should be fairly efficient. (It's thread and process safe too, not that it matters for your app.) For example: require 'fsdb' require 'yaml' db = FSDB::Database.new "~/tmp/my_data" db.formats = [FSDB::YAML_FORMAT] + db.formats 3.times do |i| db["Cat#{i}.yml"] = %w{ name1 name2 name3 } end path = "Cat1.yml" puts "Here's the object:" puts "==================" p db[path] puts "==================" puts puts "Here's the file:" puts "==================" puts File.read(File.join(db.dir, path)) puts "==================" puts and this is the output: Here's the object: ================== ["name1", "name2", "name3"] ================== Here's the file: ================== --- - name1 - name2 - name3 ================== The dir structure looks like this: [~/tmp] ls my_data Cat0.yml Cat1.yml Cat2.yml [1] http://redshift.sourceforge.net/fsdb -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407