Cache content within your Lucky application.
-
Add the dependency to your
shard.yml
:dependencies: lucky_cache: github: luckyframework/lucky_cache
-
Run
shards install
require "lucky_cache"
LuckyCache.configure do |settings|
settings.storage = LuckyCache::MemoryStore.new
settings.default_duration = 5.minutes
end
class SomeObject
include LuckyCache::Cachable
end
cache = LuckyCache.settings.storage
some_object = cache.fetch("some_key", as: SomeObject) do
SomeObject.new
end
You can cache portions of your page by including the LuckyCache::HtmlHelpers
module
in your Page class, and use the cache()
helper method.
class Posts::ShowPage < MainLayout
include LuckyCache::HtmlHelpers
needs post : Post
def content
cache("post:#{post.id}:comments", expires_in: 1.hour) do
post.comments.each do |comment|
div comment.text
end
end
end
end
- Fork it (https://github.com/luckyframework/lucky_cache/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Jeremy Woertink - maintainer
- Initial structure and some code was pulled from the original LuckyCache by @matthewmcgarvey.
- Lots of inspiration on Cache store was from @mamantoha