Skip to content

Commit

Permalink
Added 'How it works'
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjeno committed Jun 23, 2012
1 parent 8abc714 commit e20226f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ class Task < ActiveRecord::Base
end
```

## How does it work?

Catche intercepts a cached value and tags this value using the unique identifier for the given/loaded resource or collection. Once a resource expires it will expire the tagged cached values, such as the resource itself and the collection it belongs to.

```ruby
Catche::Tag::Collect.resource(@task) # { :set => ["tasks_1"], :expire => ["tasks_1"] }
Catche::Tag::Collect.collection_tags(@task, Task) # { :set => ["projects_1_tasks"], :expire => ["tasks", "projects_1_tasks"] }
```

The tags will point to different cached values, for example pointing to a cached key or a cached filepath.

## Manually expiring a cache

```ruby
Expand Down
4 changes: 2 additions & 2 deletions lib/catche/tag/collect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class << self

# Collects resource tags for a given resource
#
# Catche::Tag::Tagger.resource_tags(@task)
# Catche::Tag::Collect.resource_tags(@task)
# => { :set => ["tasks_1"], :expire => ["tasks_1"] }
def resource(resource)
set_tags = []
Expand All @@ -23,7 +23,7 @@ def resource(resource)

# Collects collection tags for a given context, for example a controller
#
# Catche::Tag::Tagger.collection_tags(controller, Task)
# Catche::Tag::Collect.collection_tags(controller, Task)
# => { :set => ["projects_1_tasks"], :expire => ["tasks", "projects_1_tasks"] }
def collection(context, resource_class, include_base=true)
associations = Catche::ResourceLoader.fetch(context, *resource_class.catche_associations)
Expand Down

0 comments on commit e20226f

Please sign in to comment.