Class: RcrewAI::Rails::Tools::RailsCacheTool

Inherits:
RCrewAI::Tools::Base
  • Object
show all
Defined in:
lib/rcrewai/rails/tools/rails_cache_tool.rb

Instance Method Summary collapse

Instance Method Details

#execute(action:, key: nil, value: nil, options: {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rcrewai/rails/tools/rails_cache_tool.rb', line 18

def execute(action:, key: nil, value: nil, options: {})
  act = action.to_sym
  opts = (options || {}).transform_keys(&:to_sym)

  case act
  when :read    then read_cache(key)
  when :write   then write_cache(key, value, opts)
  when :delete  then delete_cache(key)
  when :exist?  then cache_exists?(key)
  when :fetch   then fetch_cache(key, value, opts)
  when :clear   then clear_cache
  else { error: "Unknown action: #{action}" }
  end
rescue => e
  { error: "Cache operation failed", message: e.message }
end