GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - luckyframework/lucky_cache: Caching library for the Lucky Framework

BranchesTags
Open more actions menu

Latest commit

 

History

23 Commits
23 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
spec
spec
 
 
src
src
 
 
.ameba.yml
.ameba.yml
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
shard.yml
shard.yml
 
 

Repository files navigation

LuckyCache

Cache content within your Lucky application.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      lucky_cache:
        github: luckyframework/lucky_cache
  2. Run shards install

Adapters

LuckyCache comes with a built-in MemoryStore, but if you need extneral storage, check out one of these adapters

  • Redis Cache

Usage

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

Counters

Use increment and decrement for counters. Each call is atomic, so no updates are lost when several fibers or threads change the same key.

cache = LuckyCache.settings.storage

cache.increment("visits")                       # => 1
cache.increment("visits", by: 5)                # => 6
cache.decrement("visits")                       # => 5
cache.increment("logins", expires_in: 1.minute) # => 1

A missing or expired key starts from 0 and expires after expires_in. An existing key keeps the expiration it already had.

Page fragment cache

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

Development

Contributing

  1. Fork it (https://github.com/luckyframework/lucky_cache/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • Jeremy Woertink - maintainer

Thanks & attributions

  • Initial structure and some code was pulled from the original LuckyCache by @matthewmcgarvey.
  • Lots of inspiration on Cache store was from @mamantoha

About

Caching library for the Lucky Framework

Topics

cachecrystal-langhacktoberfest

Resources

Readme
MIT license
Activity
Custom properties

Stars

8 stars

Watchers

2 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.