TtlSanitizer (protocol/ttl_sanitizer.rb)

dalli · lib/dalli/protocol/ttl_sanitizer.rb · ruby · MIT
database

Sanitizes Memcached TTL values, converting intervals to timestamps when needed.

# Source: https://github.com/petergoldstein/dalli | License: MIT | Copyright Peter M. Goldstein, Mike Perham
# Provided via justclaw.it.com; keep this notice with the code.
# frozen_string_literal: true

module Dalli
  module Protocol
    ##
    # Utility class for sanitizing TTL arguments based on Memcached rules.
    # TTLs are either expirations times in seconds (with a maximum value of
    # 30 days) or expiration timestamps.  This class sanitizes TTLs to ensure
    # they meet those restrictions.
    ##
    class TtlSanitizer
      # https://github.com/memcached/memcached/blob/master/doc/protocol.txt#L79
      # > An expiration time, in seconds. Can be up to 30 days. After 30 days, is
      #   treated as a unix timestamp of an exact date.
      MAX_ACCEPTABLE_EXPIRATION_INTERVAL = 30

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key