CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-frozendict

A simple immutable dictionary implementation with hashing support and performance optimizations

85

1.30x
Overview
Eval results
Files

task.mdevals/scenario-2/

Configuration Cache System

Build a simple configuration cache system that stores and retrieves configuration snapshots. The system should use configurations as lookup keys and track unique configurations efficiently.

Capabilities

Store and Retrieve Configurations

Store configuration dictionaries and retrieve their associated metadata using the configuration as a lookup key.

  • Store a simple config {"debug": True} with timestamp "2024-01-01", then retrieve its timestamp successfully @test
  • Store a nested config {"db": {"host": "localhost", "port": 5432}} with timestamp "2024-01-02", verify it can be retrieved @test
  • Store the same config twice with different timestamps, verify only the first timestamp is kept @test

Check Configuration Existence

Verify whether a configuration has been stored previously.

  • Check that stored configs can be found with has_config and unknown configs return False @test

Track Unique Configurations

Count and retrieve all unique configurations stored in the cache.

  • Store three different configs, verify count_unique returns 3 @test
  • Store two configs and verify get_all_configs returns a set containing both @test

Implementation

The system should handle nested dictionaries and treat all configurations as immutable snapshots. Configurations can contain strings, numbers, booleans, and nested dictionaries.

@generates

API

class ConfigCache:
    """A cache system for storing and retrieving configuration snapshots."""

    def __init__(self):
        """Initialize the configuration cache."""
        pass

    def store_config(self, config: dict, timestamp: str) -> None:
        """
        Store a configuration snapshot with its timestamp.

        Args:
            config: Configuration dictionary (may be nested)
            timestamp: Timestamp string associated with this configuration
        """
        pass

    def get_timestamp(self, config: dict) -> str | None:
        """
        Retrieve the timestamp for a given configuration.

        Args:
            config: Configuration dictionary to look up

        Returns:
            The associated timestamp string, or None if not found
        """
        pass

    def has_config(self, config: dict) -> bool:
        """
        Check if a configuration has been stored.

        Args:
            config: Configuration dictionary to check

        Returns:
            True if the configuration exists in the cache, False otherwise
        """
        pass

    def count_unique(self) -> int:
        """
        Get the count of unique configurations stored.

        Returns:
            Number of unique configurations in the cache
        """
        pass

    def get_all_configs(self) -> set:
        """
        Get all unique configurations as a set.

        Returns:
            Set containing all stored configurations
        """
        pass

Test Cases

  • Store a simple config {"debug": True} with timestamp "2024-01-01", then retrieve its timestamp successfully @test
  • Store a nested config {"db": {"host": "localhost", "port": 5432}} with timestamp "2024-01-02", verify it can be retrieved @test
  • Store the same config twice with different timestamps, verify only the first timestamp is kept @test
  • Check that stored configs can be found with has_config and unknown configs return False @test
  • Store three different configs, verify count_unique returns 3 @test
  • Store two configs and verify get_all_configs returns a set containing both @test

Dependencies { .dependencies }

frozendict { .dependency }

Provides immutable dictionary support with hashability for use as dictionary keys and in sets.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/pypi-frozendict

tile.json