module Liquid::StrainerFactory

def add_global_filter(filter)

def add_global_filter(filter)
  strainer_class_cache.clear
  GlobalCache.add_filter(filter)
end

def create(context, filters = [])

def create(context, filters = [])
  strainer_from_cache(filters).new(context)
end

def global_filter_names

def global_filter_names
  GlobalCache.filter_method_names
end

def strainer_class_cache

def strainer_class_cache
  @strainer_class_cache ||= {}
end

def strainer_from_cache(filters)

def strainer_from_cache(filters)
  if filters.empty?
    GlobalCache
  else
    strainer_class_cache[filters] ||= begin
      klass = Class.new(GlobalCache)
      filters.each { |f| klass.add_filter(f) }
      klass
    end
  end
end