Skip to content

Downgrade cachex as the new version gets OOM#5024

Merged
IvanIvanoff merged 1 commit intomasterfrom
downgrade-cachex
Feb 27, 2026
Merged

Downgrade cachex as the new version gets OOM#5024
IvanIvanoff merged 1 commit intomasterfrom
downgrade-cachex

Conversation

@IvanIvanoff
Copy link
Member

@IvanIvanoff IvanIvanoff commented Feb 27, 2026

Changes

Ticket

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have tried to find clearer solution before commenting hard-to-understand parts of code
  • I have added tests that prove my fix is effective or that my feature works

Summary by CodeRabbit

  • Refactor
    • Improved caching system with enhanced concurrency handling and compression for better performance under load.

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 245ca01 and 34c9818.

⛔ Files ignored due to path filters (1)
  • mix.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • lib/sanbase_web/graphql/cache/cachex_provider.ex
  • lib/sanbase_web/graphql/cache/cachex_provider_4.ex
  • lib/sanbase_web/graphql/cache/cachex_provider_global.ex
  • lib/sanbase_web/graphql/cache/cachex_unlocked.ex
  • mix.exs
  • test/sanbase_web/cache/cachex_provider_test.exs

📝 Walkthrough

Walkthrough

This PR refactors the GraphQL cache provider system by introducing a new transactional locking mechanism for concurrent cache miss handling, replacing ETS-backed TTL management with Cachex-native TTL constants, deprecating the global cache provider, and downgrading the Cachex dependency from v4 to v3.

Changes

Cohort / File(s) Summary
Core Cache Provider Refactoring
lib/sanbase_web/graphql/cache/cachex_provider.ex
Replaced ETS-backed TTL handling with module constants (@default_ttl_seconds), unified expiration logic, introduced transactional miss handling with manual lock/unlock flow (obtain_lock, Unlocker), replaced nocache signaling variable, and removed obsolete TTL retrieval helpers.
New Cache Implementation
lib/sanbase_web/graphql/cache/cachex_provider_4.ex
Added comprehensive new CachexProvider module implementing the CacheProvider behaviour with Cachex-native options, compression/decompression, ETS-backed per-cache TTLs, TTL computation logic, and error mapping for Cachex results.
Deprecated Module
lib/sanbase_web/graphql/cache/cachex_provider_global.ex
Converted active module SanbaseWeb.Graphql.CachexProviderGlobal to commented-out content, effectively removing it from compilation.
Concurrency & Lock Management
lib/sanbase_web/graphql/cache/cachex_unlocked.ex
Introduced new Unlocker GenServer module to manage safety unlocks for Cachex locks, featuring scheduled termination after lock-duration windows and deferred unlock execution.
Dependencies
mix.exs
Downgraded Cachex dependency from ~> 4.0 to ~> 3.0.
Testing
test/sanbase_web/cache/cachex_provider_test.exs
Added @moduletag skip: true to disable test execution for CachexProviderTest module.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client Request
    participant Cache as Cachex Cache
    participant Lock as Lock Manager
    participant Unlocker as Unlocker Process
    participant Execute as Cache Miss Handler

    Client->>Cache: get(key)
    alt Cache Hit
        Cache-->>Client: return decompressed value
    else Cache Miss
        Client->>Lock: obtain_lock(key)
        activate Lock
        Lock-->>Client: lock acquired
        Client->>Execute: execute_cache_miss_function()
        Execute->>Execute: call function, get result
        Execute->>Cache: store result with TTL
        Execute-->>Client: return result
        Client->>Unlocker: schedule unlock after max_lock_acquired_time_ms
        activate Unlocker
        Client->>Lock: unlock(key)
        deactivate Lock
        Unlocker->>Unlocker: wait for timeout
        Unlocker->>Unlocker: self-terminate
        deactivate Unlocker
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • update cachex and cachex provider #5012: Implements opposite approach to concurrent cache handling by removing the Unlocker mechanism and shifting to Cachex.fetch with ETS-backed TTLs and Cachex v4, directly conflicting with this PR's locking strategy.

Poem

🐰 A rabbit hops through caches deep,
With locks to guard what values keep,
No more ETS, just constants true,
Cachex native, fresh and new,
Unlocker stands as safety's friend,
Concurrent writes now safely end! 🔐

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch downgrade-cachex

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@IvanIvanoff IvanIvanoff merged commit b2ee63a into master Feb 27, 2026
1 of 2 checks passed
@IvanIvanoff IvanIvanoff deleted the downgrade-cachex branch February 27, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant