cachetastic.rb

Path: lib/cachetastic.rb
Last Update: Wed Jan 02 21:36:27 -0500 2008

Gem Requirements:

  • Application Configuration
  • Ruby Extensions
  • Rails Extensions

Configuration:

  cachetastic_default_options:
    # this will dump into the log, configuration info for each cache, as well as the .inspect
    # for each object returned from the cache
    debug: true # true | false (default: false)
    # this is the type of file store to be used for this cache.
    # more stores can be developed and plugged in as desired
    store: local_memory # local_memory | memcache (default: local_memory)
    # this will marshall objects into and out of the store.
    # so far yaml is the only supported marshall format.
    marshall_method: none # none | yaml (default: none)
    # this sets how long objects will live in the cache before they are auto expired.
    default_expiry: <%= 24.hours %> # time in seconds (default: 24 hours)
    # when setting objects into the cache the expiry_swing is +/- to the expiry time.
    # example: if the expiry time is 1 hour, and the swing is 15 minutes,
    # objects will go into the cache with an expiry time sometime between 45 mins and 75 mins.
    expiry_swing: <%= 15.minutes %> # time in seconds (default: 0)
    # these options get passed on directly to the store.
    # only the memcache store uses these options currently.
    store_options: # listed below are options for memcache
      c_threshold: 10_000
      compression: true
      debug: false
      readonly: false
      urlencode: false
    # configure logging for this cache:
    logging:
      # n number of logs can be configured for a cache
      # their names can be anything you want, it's doesn't matter
      logger_1:
        # this sets the type of log you want to write to.
        # right now the only two options are file and console
        type: file # console | file (default: none)
        # if the type is file, you need to configure where the log file is to be written.
        file: log/memcached.log # relative | absolute path to log file
        # this sets the level of logging for this cache
        level: info # debug | info | warn | error | fatal (default: info)
      logger_2:
        # this sets the type of log you want to write to.
        # right now the only two options are file and console
        type: console # console | file (default: none)
        # this sets the level of logging for this cache
        level: error # debug | info | warn | error | fatal (default: info)
    # set the servers to be used for memcache
    servers:
      - 127.0.0.1:11211 # ip:port used for memcache

# if using the mongrel_page_cache_handler gem, you can configure it to use cachetastic.

  page_cache_storage: cachetastic # disk | cachetastic (default: cachetastic)

# example of how to override options for page cacheing:

  cachetastic_caches_page_cache_options:
    default_expiry: <%= 1.hour %>
    expiry_swing: <%= 15.minutes %>

# example of how to override options for rails session cacheing:

  cachetastic_caches_rails_session_cache_options:
    default_expiry: <%= 30.minutes %>

Examples:

  class MyAwesomeCache < Cachetastic::Caches::Base
  end

  MyAwesomeCache.set(1, [1,2,3])
  MyAwesomeCache.get(1) # => [1,2,3]

  class MyAwesomeCache < Cachetastic::Caches::Base
    class << self
      def get(key, x, y)
        super(key) do
          n = x + y
          set(key, n)
          n
        end
      end
    end
  end

  MyAwesomeCache.get(1, 2, 4) # => 8
  MyAwesomeCache.get(1, 4, 4) # => 8

Required files

rubygems   memcache   singleton   logger   yaml   zlib   pp   cachetastic_connection   cachetastic_logger   caches/cachetastic_caches_base   caches/cachetastic_caches_page_cache   caches/cachetastic_caches_rails_session_cache   stores/cachetastic_stores_base   stores/cachetastic_stores_memcache   stores/cachetastic_stores_local_memory   helpers/cachetastic_helpers_active_record   rails_extensions/cachetastic_active_record_base   rails_extensions/cgi_session_cachetastic_store  

[Validate]