/usr/lib/ruby/vendor_ruby/rack/cache/moneta.rb is in ruby-moneta 0.7.20-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | require 'moneta'
require 'rack/cache/key'
require 'rack/cache/metastore'
require 'rack/cache/entitystore'
module Rack
module Cache
# @api public
Moneta = {}
# @api private
module MonetaResolver
include Rack::Utils
def resolve(uri)
cache = Rack::Cache::Moneta[uri.to_s.sub(%r{^moneta://}, '')] ||=
begin
options = parse_query(uri.query)
options.keys.each do |key|
options[key.to_sym] =
case value = options.delete(key)
when 'true'; true
when 'false'; false
else value
end
end
::Moneta.new(uri.host.to_sym, options)
end
new(cache)
end
end
class MetaStore
# @api public
class Moneta < MetaStore
extend MonetaResolver
def initialize(cache)
@cache = cache
end
def read(key)
@cache[key] || []
end
def write(key, entries)
@cache[key] = entries
end
def purge(key)
@cache.delete(key)
nil
end
end
# @api public
MONETA = Moneta
end
class EntityStore
# @api public
class Moneta < EntityStore
extend MonetaResolver
def initialize(cache)
@cache = cache
end
def open(key)
data = read(key)
data && [data]
end
def exist?(key)
@cache.key?(key)
end
def read(key)
@cache[key]
end
def write(body, ttl = 0)
buf = StringIO.new
key, size = slurp(body) { |part| buf.write(part) }
@cache.store(key, buf.string, ttl == 0 ? {} : {:expires => ttl})
[key, size]
end
def purge(key)
@cache.delete(key)
nil
end
end
# @api public
MONETA = Moneta
end
end
end
|