Class: Once::Cache

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

Instance Method Summary collapse

Instance Method Details

#digest(bytes) ⇒ Object



32
33
34
35
36
# File 'lib/buildonce.rb', line 32

def digest(bytes)
  buffer = bytes.to_s.b
  pointer = buffer.empty? ? FFI::Pointer::NULL : FFI::MemoryPointer.from_string(buffer)
  decode_response(Native.once_digest_bytes(pointer, buffer.bytesize))
end

#forget_action(action_digest) ⇒ Object



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

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

#get_action_result(action_digest) ⇒ Object



60
61
62
63
# File 'lib/buildonce.rb', line 60

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

#get_blob(digest) ⇒ Object



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

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

#has_blob?(digest) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#put_action_result(result, action_digest:) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/buildonce.rb', line 52

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

#put_blob(bytes) ⇒ Object



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

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

#statsObject



69
70
71
72
73
74
75
76
77
# File 'lib/buildonce.rb', line 69

def stats
  response = decode_request(:once_cache_stats_json, {})
  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



23
24
25
26
27
28
29
30
# File 'lib/buildonce.rb', line 23

def version
  pointer = Native.once_version
  return "" if pointer.null?

  pointer.read_string
ensure
  Native.once_string_free(pointer) if pointer && !pointer.null?
end