You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,10 @@ By [Splitwise](https://www.splitwise.com)
5
5
Cacheable is a gem which intends to add method caching in an [aspect-oriented programming (AOP)](https://en.wikipedia.org/wiki/Aspect-oriented_programming) fashion in Ruby. Its core goals are:
6
6
7
7
* ease of use (method annotation)
8
-
* flexibility (simple adaptablability for any cache backend)
8
+
* flexibility (simple adaptability for any cache backend)
9
9
* portability (plain Ruby for use with any framework)
10
10
11
-
While Rails is not a requirement, Cacheable was built inside a mature Rails app and later extracted. This first release will seemlyless work in Rails and only includes an adapter for an in-memory cache backed by a simple Hash. This may be enough for you needs but it is more likely that additional cache adapters will need to be written.
11
+
While Rails is not a requirement, Cacheable was built inside a mature Rails app and later extracted. This first release will seamlessly work in Rails and only includes an adapter for an in-memory cache backed by a simple Hash. This may be enough for your needs but it is more likely that additional cache adapters will need to be written.
12
12
13
13
See more about [Cache Adapters](cache-adapters.md).
Cacheable is designed to work seemlessly with your already existings codebase. Consider the following contrived class:
35
+
Cacheable is designed to work seamlessly with your already existing codebase. Consider the following contrived class:
36
36
37
37
```ruby
38
38
classSimpleExample
@@ -62,7 +62,7 @@ class SimpleExample
62
62
end
63
63
```
64
64
65
-
**Thats it!** There's some complex Ruby magic going on under the hood but to the end user you can simply call `expensive_calculation` and the result will be retreived from the cache, if available, or generated and placed into the cache. To confirm it is working, fire up an IRB console try the following:
65
+
**That's it!** There's some complex Ruby magic going on under the hood but to the end user you can simply call `expensive_calculation` and the result will be retrieved from the cache, if available, or generated and placed into the cache. To confirm it is working, fire up an IRB console try the following:
66
66
67
67
```irb
68
68
> s = SimpleExample.new
@@ -81,7 +81,7 @@ Cacheable also adds two useful methods to your class.
81
81
82
82
#### Skip the Cache via `#{method}_without_cache`
83
83
84
-
The cache can intentionally be skipped by appending `_without_cache` to the method name. This invocation with neither check the cache nor populate it as if you called the original method and never used Cacheable.
84
+
The cache can intentionally be skipped by appending `_without_cache` to the method name. This invocation will neither check the cache nor populate it. It is as if you called the original method and never used Cacheable.
85
85
86
86
```irb
87
87
> s = SimpleExample.new
@@ -95,7 +95,7 @@ beginning expensive method
95
95
96
96
#### Remove the Value via `clear_#{method}_cache`
97
97
98
-
The cache can be cleared at any time by calling `clear_#{your_method_name}_cache`.
98
+
The cached value can be cleared at any time by calling `clear_#{your_method_name}_cache`.
99
99
100
100
```irb
101
101
> s = SimpleExample.new
@@ -151,7 +151,7 @@ So if we called `CustomKeyExample.new.my_method(123)` we would get the cache key
151
151
152
152
`"my_method called on #<CustomKeyExample:0x0…0> with Integer::123"`.
153
153
154
-
### Conditional Cacheing
154
+
### Conditional Caching
155
155
156
156
You can control if a method should be cached by supplying a proc to the `unless:` option which will get the same arguments as `key_format:`. Alternatively this method can be defined on the class and a symbol of the name of the method can be passed. **Note**: When using a symbol, the first argument will not be passed but will be available in the method as `self`. The following example will not cache the value if the first argument to the method is `false`.
You can cache class methods just as easily as a Ruby class is just an instance of `Class`. You simply need to `include Cacheable` within the `class << self` block. Methods can be defined in this block or outside using the `def self.` syntax.
Copy file name to clipboardExpand all lines: cache-adapters.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
A cache adapter is an object that Cacheable can use as an interface to your system's cache. Cacheable will work out of the box using the object returned by `Rails.cache` as a cache adapter.
4
4
5
-
The other adapter provided with the library is the [Memory Adapter](lib/cacheable/cache_adapters/memory_adapter.rb). Is a simple memoizing cache used in testing. It is little more than an object that conforms to the protocol and is backed by a Ruby Hash. When writting a new cache adapter it can be used as a template.
5
+
The other adapter provided with the library is the [Memory Adapter](lib/cacheable/cache_adapters/memory_adapter.rb). Is a simple memoizing cache used in testing. It is little more than an object that conforms to the protocol and is backed by a Ruby Hash. When writing a new cache adapter it can be used as a template.
6
6
7
7
### Protocol
8
8
@@ -16,7 +16,7 @@ There are only two methods the cache adapter protocol requires.
16
16
17
17
#### `delete(key)`
18
18
19
-
`delete` takes a key and removes it's associated value in the cache. While not currently dependend on by Cacheable, it appears the standard is to return `true` if the value was present and removed and `false` if not present to begin with.
19
+
`delete` takes a key and removes it's associated value in the cache. While not currently depended on by Cacheable, it appears the standard is to return `true` if the value was present and removed and `false` if not present to begin with.
s.summary='Add caching to any Ruby method in a aspect orientated programming approach.'
12
-
s.description='Add caching simply without modifying your existing code. Inlcudes configurable options for simple cache invalidation. See README on github for more information.'
11
+
s.description='Add caching simply without modifying your existing code. '\
12
+
'Includes configurable options for simple cache invalidation. '\
0 commit comments