Skip to content

fix(acp): replace global _ACP_CACHE_DIR with @lru_cache#559

Open
github-actions[bot] wants to merge 1 commit intomainfrom
fix/code-quality/replace-global-cache-dir
Open

fix(acp): replace global _ACP_CACHE_DIR with @lru_cache#559
github-actions[bot] wants to merge 1 commit intomainfrom
fix/code-quality/replace-global-cache-dir

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 2, 2026

Summary

Replaces module-level global state for caching the ACP cache directory with functools.lru_cache decorator. This is a cleaner pattern that avoids mutable module-level state while maintaining the same lazy initialization behavior.

Changes

  • Removed global _ACP_CACHE_DIR variable
  • Added @lru_cache(maxsize=1) decorator to get_acp_cache_dir() function
  • Simplified function body by removing global state management

Before:

_ACP_CACHE_DIR: Path | None = None

def get_acp_cache_dir() -> Path:
    global _ACP_CACHE_DIR
    if _ACP_CACHE_DIR is None:
        _ACP_CACHE_DIR = Path.home() / ".openhands" / "cache" / "acp"
        _ACP_CACHE_DIR.mkdir(parents=True, exist_ok=True)
    return _ACP_CACHE_DIR

After:

@lru_cache(maxsize=1)
def get_acp_cache_dir() -> Path:
    cache_dir = Path.home() / ".openhands" / "cache" / "acp"
    cache_dir.mkdir(parents=True, exist_ok=True)
    return cache_dir

Related Issue

Addresses findings from #557

Testing

  • Linting passes (make lint)
  • Tests pass (make test) - 1261 tests passed

This PR was automatically generated by the Code Quality Report workflow.

Replaces module-level global state for caching the ACP cache directory
with functools.lru_cache decorator. This is a cleaner pattern that
avoids mutable module-level state while maintaining the same lazy
initialization behavior.

Before:
  _ACP_CACHE_DIR: Path | None = None

  def get_acp_cache_dir() -> Path:
      global _ACP_CACHE_DIR
      if _ACP_CACHE_DIR is None:
          _ACP_CACHE_DIR = ...
      return _ACP_CACHE_DIR

After:
  @lru_cache(maxsize=1)
  def get_acp_cache_dir() -> Path:
      cache_dir = ...
      return cache_dir

Addresses item from code quality report.

Closes #557

Co-authored-by: openhands <openhands@all-hands.dev>
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.

0 participants