https://github.com/rossta/cache_cow
Rails cache extensions for models
https://github.com/rossta/cache_cow
Last synced: about 1 year ago
JSON representation
Rails cache extensions for models
- Host: GitHub
- URL: https://github.com/rossta/cache_cow
- Owner: rossta
- License: mit
- Created: 2011-10-26T14:03:36.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-10-27T11:54:32.000Z (over 14 years ago)
- Last Synced: 2025-01-03T04:38:02.933Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 125 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# CacheCow
CacheCow allows ActiveRecord models to `acts_as_cached``
## Install
In your Gemfile
gem "cache_cow"
Or via command line
gem install cache_cow
## Overview
CacheCow provides an api for caching results of methods and associations on ActiveRecord models.
To use in a model, declare `acts_as_cached`
``` ruby
class Post
acts_as_cached
end
```
Instances of a cache_cow model can read, write, fetch, and expire their own cache keys. Cache keys
are namespaced and versioned by convention as :::. An instances
id is the cache suffix be default.
``` ruby
# Post.cache_cow_version = 1
post = Post.find(123)
post.fetch_cache { "great post" } # fetches from cache key 'Post:1:123', store 'great post' on cache miss
post.write_cache("foo", "bar") # writes 'bar to cache key 'Post:1:123:foo'
post.read_cache("foo") # returns 'bar' from cache key 'Post:1:123:foo'
````