Skip to content

Conversation

@orrk-litt
Copy link
Contributor

@orrk-litt orrk-litt commented Nov 10, 2025

Solves #1272
Add EvictionStrategy option, allowing fixed eviction where entries are deleted after TTL passes (even if accessed)

Tests

  • Simple unit tests
  • Changed manually eviction time from Days to Seconds, tested both strategy with client and requests

Summary by CodeRabbit

  • New Features

    • Added CLI flag -es/-eviction-strategy to configure interaction data eviction behavior with two options: "sliding" (default, TTL extends on access) and "fixed" (TTL fixed from write time).
  • Tests

    • Added tests validating sliding and fixed eviction strategy behaviors.

@coderabbitai
Copy link

coderabbitai bot commented Nov 10, 2025

Walkthrough

The pull request introduces a configurable eviction strategy feature for the Interactsh server. A new CLI flag -eviction-strategy (with short form -es) allows users to select between "sliding" (TTL reset on access) and "fixed" (TTL from write time) eviction policies. The implementation spans CLI parsing, options propagation, type definitions, and cache behavior changes.

Changes

Cohort / File(s) Summary
Documentation
README.md
Documents new -es / -eviction-strategy CLI flag with sliding/fixed options and default "sliding" value.
CLI Configuration
cmd/interactsh-server/main.go
Parses new eviction-strategy flag, maps string values to storage.EvictionStrategy constants, and propagates to storage options. Adds EvictionStrategy field to CLIServerOptions.
Options Structures
pkg/options/server_options.go, pkg/storage/option.go
Adds EvictionStrategy string field to CLIServerOptions; introduces EvictionStrategy type with EvictionStrategySliding and EvictionStrategyFixed constants; adds EvictionStrategy field to storage.Options with default "Sliding".
Storage Implementation
pkg/storage/storagedb.go
Implements strategy-dependent TTL behavior: EvictionStrategyFixed uses expire-after-write, EvictionStrategySliding uses expire-after-access; replaces unconditional expire-after-access with switch-based selection.
Tests
pkg/storage/storagedb_test.go
Adds TestSlidingEvictionStrategy and TestFixedEvictionStrategy to validate TTL behavior differences between strategies.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI Parser
    participant Opts as storage.Options
    participant DB as StorageDB
    participant Cache as TTL Cache

    CLI->>Opts: Set EvictionStrategy (Sliding/Fixed)
    
    rect rgba(200, 220, 255, 0.3)
    Note over DB,Cache: Sliding Strategy (expire-after-access)
    DB->>DB: EvictionStrategy == Sliding?
    DB->>Cache: Configure ExpireAfterAccess
    Cache->>Cache: Extend TTL on access
    end
    
    rect rgba(255, 200, 200, 0.3)
    Note over DB,Cache: Fixed Strategy (expire-after-write)
    DB->>DB: EvictionStrategy == Fixed?
    DB->>Cache: Configure ExpireAfterWrite
    Cache->>Cache: TTL fixed from write time
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Files spread across multiple layers: Configuration, options, storage, and tests require understanding the feature end-to-end.
  • Logic change in storagedb.go: The switch-based eviction strategy selection introduces new conditional logic that should be validated for correctness.
  • Test coverage: Review test assertions to ensure both strategies are exercised with proper timing and access patterns.
  • Potential gaps: Verify that the EvictionStrategy field in CLIServerOptions is properly wired through AsServerOptions if needed.

Poem

🐰 Hop through the caches, old and new,
Fixed paths and sliding views—
Pick your strategy, choose your way,
Eviction happens, come what may!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an eviction strategy feature to the server. It is concise, specific, and directly reflects the primary functionality being introduced.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/storage/storagedb_test.go (1)

163-181: LGTM! Fixed eviction test correctly validates TTL independence from access.

The test properly verifies that accessing an entry does NOT extend its TTL in fixed mode, confirming expire-after-write behavior.

Optional: Consider slightly larger timing buffers for test robustness.

The tests use 100ms TTL with 10ms buffers. While this should be sufficient, slightly larger buffers (e.g., 20-50ms) could reduce flakiness on slower CI systems. This is optional and not urgent since the current values are reasonable.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bcbfdb9 and 2f2071b.

📒 Files selected for processing (6)
  • README.md (1 hunks)
  • cmd/interactsh-server/main.go (2 hunks)
  • pkg/options/server_options.go (1 hunks)
  • pkg/storage/option.go (1 hunks)
  • pkg/storage/storagedb.go (1 hunks)
  • pkg/storage/storagedb_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
cmd/interactsh-server/main.go (1)
pkg/storage/option.go (4)
  • EvictionStrategy (5-5)
  • EvictionStrategyFixed (9-9)
  • EvictionStrategySliding (8-8)
  • DefaultOptions (23-26)
pkg/options/server_options.go (1)
pkg/storage/option.go (1)
  • EvictionStrategy (5-5)
pkg/storage/storagedb_test.go (2)
pkg/storage/storagedb.go (1)
  • New (35-75)
pkg/storage/option.go (4)
  • Options (12-17)
  • EvictionStrategy (5-5)
  • EvictionStrategySliding (8-8)
  • EvictionStrategyFixed (9-9)
pkg/storage/storagedb.go (1)
pkg/storage/option.go (3)
  • EvictionStrategy (5-5)
  • EvictionStrategyFixed (9-9)
  • EvictionStrategySliding (8-8)
🔇 Additional comments (10)
README.md (1)

356-356: LGTM! Clear documentation of the new eviction strategy flag.

The documentation follows the established format and clearly specifies the available options and default value.

pkg/options/server_options.go (1)

23-23: LGTM! Field addition is consistent with the existing pattern.

The EvictionStrategy field captures CLI input and is mapped to storage options in main.go, following the same pattern as the Eviction and NoEviction fields.

pkg/storage/storagedb.go (1)

41-48: LGTM! Eviction strategy implementation is correct.

The switch correctly implements the two eviction strategies:

  • Fixed: TTL counted from write time (expire-after-write)
  • Sliding: TTL counted from last access (expire-after-access, backward compatible default)
pkg/storage/storagedb_test.go (1)

137-161: LGTM! Sliding eviction test correctly validates TTL extension on access.

The test properly verifies that accessing an entry extends its TTL in sliding mode.

pkg/storage/option.go (3)

5-10: LGTM! Clean enum definition with clear documentation.

The EvictionStrategy type and constants are well-defined with helpful comments explaining the behavior of each strategy.


16-16: LGTM! Field addition enables configurable eviction strategy.


24-25: LGTM! Default to sliding strategy maintains backward compatibility.

Setting EvictionStrategySliding as the default preserves the original expire-after-access behavior.

cmd/interactsh-server/main.go (3)

51-51: LGTM! Flag definition follows established patterns.

The eviction strategy flag is properly defined with a sensible default value.


223-232: LGTM! Robust parsing and validation of eviction strategy.

The implementation correctly:

  • Uses case-insensitive matching for user convenience
  • Maps string values to typed constants
  • Provides clear error messaging for invalid input

237-237: LGTM! Eviction strategy correctly propagated to storage options.

@dogancanbakir dogancanbakir linked an issue Nov 23, 2025 that may be closed by this pull request
@Mzack9999 Mzack9999 merged commit f9a1dd1 into projectdiscovery:main Nov 24, 2025
6 checks passed
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.

Add option for cache.WithExpireAfterWrite

3 participants