Class: PostHog::MCP::IdentityCache Private
- Inherits:
-
Object
- Object
- PostHog::MCP::IdentityCache
- Defined in:
- lib/posthog/mcp/identity.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Bounded LRU of session identities, isolated per server.
Instance Method Summary collapse
- #get(session_id) ⇒ Object private
- #has?(session_id) ⇒ Boolean private
-
#initialize(max_size = 1000) ⇒ IdentityCache
constructor
private
A new instance of IdentityCache.
-
#merge!(session_id, identity) ⇒ Array(UserIdentity, Boolean)
private
Atomically read the cached identity, merge the new one, store it, and report whether it changed.
- #set(session_id, identity) ⇒ Object private
- #size ⇒ Object private
Constructor Details
#initialize(max_size = 1000) ⇒ IdentityCache
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of IdentityCache.
11 12 13 14 15 |
# File 'lib/posthog/mcp/identity.rb', line 11 def initialize(max_size = 1000) @cache = {} @max_size = max_size @mutex = Mutex.new end |
Instance Method Details
#get(session_id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 20 21 22 23 24 |
# File 'lib/posthog/mcp/identity.rb', line 17 def get(session_id) @mutex.synchronize do identity = @cache.delete(session_id) next nil if identity.nil? @cache[session_id] = identity end end |
#has?(session_id) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 |
# File 'lib/posthog/mcp/identity.rb', line 50 def has?(session_id) @mutex.synchronize { @cache.key?(session_id) } end |
#merge!(session_id, identity) ⇒ Array(UserIdentity, Boolean)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Atomically read the cached identity, merge the new one, store it, and report whether it changed. Keeps concurrent requests for one session from interleaving their read-merge-write.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/posthog/mcp/identity.rb', line 39 def merge!(session_id, identity) @mutex.synchronize do previous = @cache.delete(session_id) merged = Identity.merge_identities(previous, identity) changed = !(previous && Identity.identities_equal?(previous, merged)) @cache.shift if @cache.length >= @max_size @cache[session_id] = merged [merged, changed] end end |
#set(session_id, identity) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 30 31 32 |
# File 'lib/posthog/mcp/identity.rb', line 26 def set(session_id, identity) @mutex.synchronize do @cache.delete(session_id) @cache.shift if @cache.length >= @max_size @cache[session_id] = identity end end |
#size ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/posthog/mcp/identity.rb', line 54 def size @mutex.synchronize { @cache.length } end |