Skip to content

Use persistent cache for temp reglists instead of tempdir() - #53

Closed
jefferis wants to merge 1 commit into
masterfrom
fix/persistent-reglist-cache
Closed

jefferis wants to merge 1 commit into
masterfrom
fix/persistent-reglist-cache

Conversation

@jefferis

@jefferis jefferis commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • macOS cleans up tempdir() files after 3 days of inactivity, causing compound registrations saved with add_reglist(temp=TRUE) to disappear during long-running R sessions
  • Changed to use tools::R_user_dir("nat.templatebrains", "cache") with session-specific subfolders
  • Each session gets its own folder named after basename(tempdir()) (e.g., RtmpeWpUOg)
  • A .tempdir_path marker file tracks the original tempdir, and stale session folders are cleaned up when a new session detects the original tempdir no longer exists
  • This bumps the minimum R version to 4.0

How it works

  1. On add_reglist(temp=TRUE), files go to ~/.../cache/nat.templatebrains/tempreglists/RtmpXXXXX/
  2. A .tempdir_path marker stores the full original tempdir() path
  3. On subsequent calls, cleanup_stale_reglist_sessions() checks each session folder's marker
  4. If the original tempdir no longer exists, that session has ended and its folder is removed

Test plan

  • Verify session-specific folders are created in cache location
  • Verify .tempdir_path marker is written
  • Verify stale session folders are cleaned up when original tempdir is gone
  • Verify malecns bridging registrations persist during long sessions

🤖 Generated with Claude Code

macOS cleans up tempdir() files after 3 days of inactivity, causing
compound registrations saved with add_reglist(temp=TRUE) to disappear
during long-running R sessions.

Changed to use tools::R_user_dir("nat.templatebrains", "cache") with
session-specific subfolders (using basename(tempdir()) as session ID).
A marker file stores the original tempdir path, and stale session
folders are cleaned up when a new session detects the original
tempdir no longer exists.

This requires R >= 4.0 (updated in DESCRIPTION).
@jefferis
jefferis force-pushed the fix/persistent-reglist-cache branch from 3f5faaf to 7c1ad53 Compare March 8, 2026 00:10
jefferis added a commit that referenced this pull request Mar 8, 2026
Replaces disk-based storage in tempdir with in-memory caching via
cachem::cache_mem(). This avoids macOS tempdir cleanup issues during
long-running R sessions.

Key changes:
- add_reglist(temp=TRUE) now stores serialized reglists in memory
- Serialization breaks environment references, avoiding memory leaks
- allreg_dataframe() includes memory-cached entries with memory:// prefix
- make_reglist() handles memory:// paths in bridging sequences

Benefits:
- CRAN compliant (no file system writes)
- No tempdir cleanup issues on any platform
- Simpler than disk-based caching

See also PR #53 for alternative disk-based approach (superseded by this).
jefferis added a commit that referenced this pull request Mar 8, 2026
Replaces disk-based storage in tempdir with in-memory caching via
cachem::cache_mem(). This avoids macOS tempdir cleanup issues during
long-running R sessions.

Key changes:
- add_reglist(temp=TRUE) now stores serialized reglists in memory
- Serialization breaks environment references, avoiding memory leaks
- allreg_dataframe() includes memory-cached entries with memory:// prefix
- make_reglist() handles memory:// paths in bridging sequences

Benefits:
- CRAN compliant (no file system writes)
- No tempdir cleanup issues on any platform
- Simpler than disk-based caching

See also PR #53 for alternative disk-based approach (superseded by this).
jefferis added a commit that referenced this pull request Mar 8, 2026
Replaces disk-based storage in tempdir with in-memory caching using a
simple environment. This avoids macOS tempdir cleanup issues during
long-running R sessions.

Key changes:
- add_reglist(temp=TRUE) now stores serialized reglists in memory
- Serialization breaks environment references, avoiding memory leaks
- allreg_dataframe() includes memory-cached entries with memory:// prefix
- make_reglist() handles memory:// paths in bridging sequences

Benefits:
- CRAN compliant (no file system writes)
- No tempdir cleanup issues on any platform
- Simpler than disk-based caching
- No new dependencies (uses base R environment)

See also PR #53 for alternative disk-based approach (superseded by this).
@jefferis jefferis closed this Mar 20, 2026
@jefferis
jefferis deleted the fix/persistent-reglist-cache branch March 20, 2026 23:20
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