<commit_before>class Job < ActiveRecord::Base
  module JobDevice
    extend ActiveSupport::Concern

    def device_type
      device_details['formal_name'] 
    end

    def device_name
      device_details['name']
    end
    
    def device_details
      if device_id
        begin
          Rails.cache.fetch("device_#{device_id}") do
            devicedb = DeviceDBComms::Device.new
            devicedb.find(device_id)
          end
        rescue => e
          Rails.logger.info "*"*50
          Rails.logger.info "Failed to connect to DeviceDB: #{e.backtrace}"
          Rails.logger.info "*"*50
          Hash.new('')
        end
      else
        Hash.new('')
      end
    end
    
  end
end
<commit_msg>Add a cache timeout<commit_after>class Job < ActiveRecord::Base
  module JobDevice
    extend ActiveSupport::Concern

    def device_type
      device_details['formal_name'] 
    end

    def device_name
      device_details['name']
    end
    
    def device_details
      if device_id
        begin
          Rails.cache.fetch("device_#{device_id}", expires_in: 5.minutes) do
            devicedb = DeviceDBComms::Device.new
            devicedb.find(device_id)
          end
        rescue => e
          Rails.logger.info "*"*50
          Rails.logger.info "Failed to connect to DeviceDB: #{e.backtrace}"
          Rails.logger.info "*"*50
          Hash.new('')
        end
      else
        Hash.new('')
      end
    end
    
  end
end

{'fraction_non_alphanumeric': 0.09103353867214237, 'fraction_numerical': 0.006160164271047228, 'mean_word_length': 1.8388349514563107, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4212274', 'n_tokens_mistral': 453, 'n_tokens_neox': 440, 'n_words': 99}