Sha256: 57afa9d2455bb604a304117cd06e2741033f8aeba9437978c81a0d517d632a02

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

# Catche [![Build Status](https://secure.travis-ci.org/Arjeno/catche.png?branch=master)](http://travis-ci.org/Arjeno/catche)

Catche is a caching library for Ruby on Rails. It automates automated resource and collection caching/expiration. It basically tags cached outputs and expires those tags based on configuration.

## Installation

Add this to your Gemfile and run `bundle`.
```
gem "catche"
```

## Controller caching

Controller caching is based on `caches_action` using the method `catche`.

### Simple caching

```ruby
class ProjectsController < ApplicationController
  catche Project, :index, :show
end
```

### Associative caching

For advanced usage such as advanced caching you need to configure this in the model.

```ruby
class Task < ActiveRecord::Base
  catche :through => :project
end
```

```ruby
class TasksController < ApplicationController
  catche Task, :index, :show
end
```

On resource `update` and `destroy` this will expire:

* Resource: `tasks_1`
* Collection: `tasks`
* Collection: `projects_1_tasks_1`

On resource `create` this will expire:

* Collection: `tasks`
* Collection: `projects_1_tasks_1`

You can use as many associations as you would like;

```ruby
class Task < ActiveRecord::Base
  catche :through => [:user, :project]
end
```

### Advanced configuration

```ruby
class TasksController < ApplicationController
  catche(
    Task,                       # Configured cached model
    :index, :show,              # Actions
    {
      :resource_name => :task,  # Name of your resource, defaults to your model name
    }
  )
end
```

```ruby
class Task < ActiveRecord::Base
  catche(
    :through        => [:user, :project], # Associations
    :tag_identifier => :id,               # Unique identifier for the resource
    :class          => Task,              # Class to use as tag scope
    :collection_tag => 'tasks',           # Name of the tag scope for this model,
  )
end
```

## License

This project is released under the MIT license.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
catche-0.2 README.md