def lut_write_cache_item(lut_key, lut_item_count, lut_data)
      prefix  = lut_options(lut_key)[:prefix]
      success = Rails.cache.write("#{prefix}#{lut_key}/#{lut_item_count}", lut_data)

      # Do some magic here and just throw a warning
      # * Divide and conquer on error
      if !success
        warn "WARNING - LookUpTable: Cache.write failed, trying to 'divide and conquer'"

        if lut_data.respond_to?(:keys) && lut_data.respond_to?(:values)
          # Got a hash
          keys        = lut_data.keys
          keys_length = keys.length

          if keys_length < 2
            # Try to slice down values
            entries = lut_data[keys.first].entries

            first_entries  = { keys.first => entries.slice!(0, entries.length/2) }
            second_entries = { keys.first => entries }

            lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count, first_entries)
            lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count + 1, second_entries)

          else
            first_keys  = keys.slice!(0, keys.length/2)
            second_keys = keys
            first_hash  = {}
            second_hash = {}

            first_keys.each  { |k| first_hash[k]  = lut_data[k] }
            second_keys.each { |k| second_hash[k] = lut_data[k] }

            lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count, first_hash)
            lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count + 1, second_hash)
          end
        elsif lut_data.respond_to?(:entries)
          # Got an Array or a Set
          entries = lut_data.entries
          first_entries  = entries.slice!(0, entries.length/2)
          second_entries = entries

          lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count, first_entries)
          lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count + 1, second_entries)
        else
          # Finally we can't help here
          raise "Cache::write failed - Try lower :batch_size"
        end
      end

      return lut_item_count
    end
def lut_write_cache_item(lut_key, lut_item_count, lut_data)
      prefix  = lut_options(lut_key)[:prefix]
      success = Rails.cache.write("#{prefix}#{lut_key}/#{lut_item_count}", lut_data)

      # Do some magic here and just throw a warning
      # * Divide and conquer on error
      if !success
        warn "WARNING - LookUpTable: Cache.write failed, trying to 'divide and conquer'"

        if lut_data.respond_to?(:keys) && lut_data.respond_to?(:values)
          # Got a hash
          keys        = lut_data.keys
          keys_length = keys.length

          if keys_length < 2
            # Try to slice down values
            entries = lut_data[keys.first].entries

            first_entries  = { keys.first => entries.slice!(0, entries.length/2) }
            second_entries = { keys.first => entries }

            lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count, first_entries)
            lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count + 1, second_entries)

          else
            first_keys  = keys.slice!(0, keys.length/2)
            second_keys = keys
            first_hash  = {}
            second_hash = {}

            first_keys.each  { |k| first_hash[k]  = lut_data[k] }
            second_keys.each { |k| second_hash[k] = lut_data[k] }

            lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count, first_hash)
            lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count + 1, second_hash)
          end
        elsif lut_data.respond_to?(:entries)
          # Got an Array or a Set
          entries = lut_data.entries
          first_entries  = entries.slice!(0, entries.length/2)
          second_entries = entries

          lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count, first_entries)
          lut_item_count = self.lut_write_cache_item(lut_key, lut_item_count + 1, second_entries)
        else
          # Finally we can't help here
          raise "Cache::write failed - Try lower :batch_size"
        end
      end

      return lut_item_count
    end
Write a single Item into LookUpTable-Cache
 TODO: refactor