Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

sleewoo / el   ruby

Repository URL to install this package:

/ docs / CacheManager.md

Cache Manager

Allows to cache the result of an arbitrary block and use the result on consequent requests.

Note: Value is not stored if block returns false or nil.

Cache can be cleared by calling clear_cache! method.

If called without params, all cache will be cleared.

To clear only specific blocks, pass their IDs as params.

Example:

class App < E

  def index
    @db_items = cache :db_items do
      # fetching items
    end
    @banners = cache :banners do
      # render banners partial
    end
    # ...
  end

  def products
    cache do
      # fetch and render products
    end
  end

  after do
    if 'some condition occurred'
      # clearing cache only for @banners and @db_items
      clear_cache! :banners, :db_items
    end
    if 'some another condition occurred'
      # clearing all cache
      clear_cache!
    end
  end
end

By default, the cache will be kept in memory. If you want to use a different pool, set it by using cache_pool at app level.

Just make sure your pool behaves like a Hash, Meant it should respond to []=, [], delete and clear.

# controllers...

app = E.new do
  cache_pool SomePool
  mount Something
end
app.run

[ contents ↑ ]