A work in progress, not production ready.
PostgresCache is a Rails/Rack cache backed by a PostgresUNLOGGED
table andbytea
column.
How to use:
# This will create the table `application_cache` in your databasecache=PostgresCache.new("YOUR_POSTGRES_DATABASE_URL",table_name:"application_cache")# Now you can store any Ruby object that can be marshaled in the database under a keycache.write("your key","some value")cache.exists?("your key")cache.read("your key")cache.fetch("another key")do"default value if not exists"endcache.delete("your key")cache.clear
There is a wrapper for use as a Rails.cache:
Rails.application.config.cache=ActiveSupport::Cache::Postgres.new("YOUR_POSTGRES_DATABASE_URL")
Or as a Rack::Cache (not working correctly yet):
entity_store=Rack::Cache::EntityStore::Postgres.new("YOUR_POSTGRES_DATABASE_URL")meta_store=Rack::Cache::MetaStore::Postgres.new("YOUR_POSTGRES_DATABASE_URL")