Class: Once::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/buildonce.rb

Instance Method Summary collapse

Constructor Details

#initialize(local_cache_root: nil, workspace_root: nil) ⇒ Cache

Returns a new instance of Cache.



28
29
30
31
32
33
34
35
36
37
# File 'lib/buildonce.rb', line 28

def initialize(local_cache_root: nil, workspace_root: nil)
  if local_cache_root && workspace_root
    raise ArgumentError, "local_cache_root and workspace_root cannot be used together"
  end

  @selection = {}
  @selection[:local_cache_root] = local_cache_root.to_s if local_cache_root
  @selection[:workspace_root] = workspace_root.to_s if workspace_root
  @selection.freeze
end

Instance Method Details

#digest(bytes) ⇒ Object



43
44
45
46
47
# File 'lib/buildonce.rb', line 43

def digest(bytes)
  buffer = bytes.to_s.b
  pointer = memory_pointer(buffer)
  decode_response(Native.once_digest_bytes(pointer, buffer.bytesize))
end

#forget_action(action_digest) ⇒ Object



92
93
94
95
96
97
# File 'lib/buildonce.rb', line 92

def forget_action(action_digest)
  decode_request(
    :once_cache_forget_action_json,
    selection(action_digest: action_digest),
  )
end

#get_action_result(action_digest) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/buildonce.rb', line 84

def get_action_result(action_digest)
  response = decode_request(
    :once_cache_get_action_result_json,
    selection(action_digest: action_digest),
  )
  response && action_result_from_native(response)
end

#get_blob(digest) ⇒ Object



58
59
60
61
# File 'lib/buildonce.rb', line 58

def get_blob(digest)
  response = decode_request(:once_cache_get_blob_json, selection(digest: digest))
  response.fetch("bytes").pack("C*")
end

#get_blob_to_file(digest, path) ⇒ Object



63
64
65
66
67
68
# File 'lib/buildonce.rb', line 63

def get_blob_to_file(digest, path)
  decode_request(
    :once_cache_get_blob_to_file_json,
    selection(digest: digest, path: path.to_s),
  )
end

#has_blob?(digest) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/buildonce.rb', line 70

def has_blob?(digest)
  decode_request(:once_cache_has_blob_json, selection(digest: digest))
end

#put_action_result(result, action_digest:) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/buildonce.rb', line 74

def put_action_result(result, action_digest:)
  decode_request(
    :once_cache_put_action_result_json,
    selection(
      action_digest: action_digest,
      result: normalize_action_result(result),
    ),
  )
end

#put_blob(bytes) ⇒ Object



49
50
51
52
# File 'lib/buildonce.rb', line 49

def put_blob(bytes)
  buffer = bytes.to_s.b
  decode_request(:once_cache_put_blob_json, selection(bytes: buffer.bytes))
end

#put_file(path) ⇒ Object



54
55
56
# File 'lib/buildonce.rb', line 54

def put_file(path)
  decode_request(:once_cache_put_file_json, selection(path: path.to_s))
end

#statsObject



99
100
101
102
103
104
105
106
107
# File 'lib/buildonce.rb', line 99

def stats
  response = decode_request(:once_cache_stats_json, @selection)
  CacheStats.new(
    blob_count: response.fetch("blob_count"),
    blob_bytes: response.fetch("blob_bytes"),
    action_count: response.fetch("action_count"),
    action_bytes: response.fetch("action_bytes"),
  )
end

#versionObject



39
40
41
# File 'lib/buildonce.rb', line 39

def version
  read_native_string(Native.once_version)
end