views:

259

answers:

1

What I Want

I want to read the cache of Safari through Active Record. Essentially, I want to peek inside the cache like this except from within a Rails app.

What I've Tried

I copied the Cache.db file I set up the environment.rb file in a new Rails app with the path of a copy of the Safari Cache.db SQLite Database. Ran db:migrate

This seems to generate a schema, but I'm not sure how I read this data now. The schema also has an error:

# Could not dump table "cfurl_cache_response" because of following StandardError
#   Unknown type '' for column 'time_stamp'

I think I'm going down the wrong road here.

Requirements

  • I don't want to write any data, just read it.
  • I want to read the URL and HTML of pages stored in the cache.
  • Something dead simple - I'm a Rails newbie.
  • Quick to implement - this is for a quick and dirty prototype.

What's the Best Approach?

Should I be connecting to the Safari cache through a second SQLite database where I can construct a read only query of the data? Then somehow read this in turn through my Rails app?

+2  A: 

If you only want to read from it, your might as well just use the sqlite3 gem http://sqlite-ruby.rubyforge.org/:

gem install sqlite3-ruby

Then in ruby:

require 'rubygems'
require 'sqlite3'

db = SQLite3::Database.new('/Users/Andrew/Library/Caches/com.apple.Safari')

Then you can read it using normal sql:

db.execute 'SELECT * FROM cfurl_cache_response'
Andrew Nesbitt
Talk about the simplest possible thing that will work. This is perfect - just what I was after. Thankyou!
John Gallagher