Skip to content

Enhanced KeyValueStore with Query Caching and Demo Integration#145

Open
GoogolC wants to merge 4 commits into
lynxworld:devfrom
GoogolC:feature-keyvalue-store
Open

Enhanced KeyValueStore with Query Caching and Demo Integration#145
GoogolC wants to merge 4 commits into
lynxworld:devfrom
GoogolC:feature-keyvalue-store

Conversation

@GoogolC

@GoogolC GoogolC commented Dec 16, 2024

Copy link
Copy Markdown

This PR enhances the KeyValueStore functionality and aligns it better with Lynx's architecture by introducing query caching capabilities and a demo project for showcasing usage.


Changes

This PR enhances the KeyValueStore functionality and aligns it better with Lynx's architecture by introducing query caching capabilities and a demo project for showcasing usage.

Key Changes

  1. Enhanced KeyValueStore:

    • Added support for caching database query results:
      • cacheQueryResult(query: String, result: String): Stores a query result with a unique key.
      • getCachedResult(query: String): Option[String]: Retrieves cached query results.
    • Retains functionality for reading and writing key-value pairs:
      • read(): Reads all key-value pairs from a file.
      • write(data: Map[String, String]): Writes key-value pairs to a file.
      • append(key: String, value: String): Appends a single key-value pair.
  2. Demo Project (demo/src/main/scala/DemoKeyValueStoreApp.scala):

    • Demonstrates real-world usage of KeyValueStore:
      • Writing and reading key-value pairs.
      • Caching and retrieving database query results.
    • Includes meaningful examples such as simulating query result caching in a database system.
  3. Unit Testing (demo/src/test/scala/DemoKeyValueStoreTest.scala):

    • Comprehensive tests for:
      • Writing and reading key-value pairs.
      • Caching and retrieving query results.
    • Ensures the correctness and stability of all methods.

Features

  • File-Based Key-Value Storage:
    • Simple and intuitive file-based storage for key-value pairs.
  • Query Caching:
    • Cache query results for repeated use, improving efficiency.
  • Demo and Tests:
    • Provides a clear demonstration of how to use KeyValueStore effectively.
    • Fully tested to ensure reliability.

Test Plan

How to Test

  1. Run the Demo:

    • Navigate to the repository's root directory and compile the code:
      scalac -d out demo/src/main/scala/DemoKeyValueStoreApp.scala src/main/scala/org/grapheco/lynx/KeyValueStore.scala
    • Execute the demo application:
      scala -cp out demo.DemoKeyValueStoreApp
    • Expected Output:
      === Demo: KeyValueStore ===
      
      Writing key-value pairs...
      
      Reading key-value pairs...
      user1 -> Alice
      user2 -> Bob
      
      Caching a query result...
      
      Retrieving cached query result...
      Cached result for query: [{'name':'Alice'}, {'name':'Bob'}]
      
  2. Run Unit Tests:

    • Compile and run the test file:
      scalac -d out demo/src/test/scala/DemoKeyValueStoreTest.scala src/main/scala/org/grapheco/lynx/KeyValueStore.scala
      scala -cp out demo.DemoKeyValueStoreTest
    • Expected Output:
      Testing append()...
      Testing read()...
      Testing cacheQueryResult()...
      Testing getCachedResult()...
      All tests passed!
      

Future Improvements

  • Extend KeyValueStore to handle more complex caching policies (e.g., TTL for cached data).
  • Introduce configurable file paths and better error handling for edge cases.
  • Explore integration with Lynx's core architecture, making KeyValueStore an optional utility.

Why This PR?

This PR is aligned with feedback suggesting a transformation of KeyValueStore into a demonstration project. By integrating query caching functionality and providing a clear demo with unit tests, this PR illustrates how KeyValueStore can be a useful utility in a Lynx ecosystem or as an independent module.


Summary

This PR introduces:

  • An enhanced KeyValueStore with query caching capabilities.
  • A demo project illustrating practical use cases.
  • Comprehensive test coverage for all implemented features.

I believe this contribution can serve as a valuable demonstration of KeyValueStore's potential and its application in real-world scenarios.


@GoogolC

GoogolC commented Dec 16, 2024

Copy link
Copy Markdown
Author

From Googolc Team

@HC-teemo

Copy link
Copy Markdown
Collaborator

Great PR. but, in fact, Lynx does not need a storage layer. If used as an adapter, it probably needs better designing, and more testing.

@excelwang

Copy link
Copy Markdown
Contributor

Authors of this pr could consider making the code to be a demo project using lynx.

@GoogolC

GoogolC commented Jan 7, 2025

Copy link
Copy Markdown
Author

I have addressed the feedback by transforming KeyValueStore into a standalone demo project, better aligning with Lynx's architecture. This update includes restructuring the code, enhancing functionality with query caching, adding comprehensive unit tests, and providing a practical demo application to showcase its usage in real-world scenarios.
Please let me know if further refinements are required. Thank you for your valuable feedback!

@GoogolC GoogolC changed the title Add KeyValueStore with basic read/write functionality and tests Enhance Lynx with a KeyValueStore Utility and Demo Project Jan 7, 2025
@GoogolC GoogolC changed the title Enhance Lynx with a KeyValueStore Utility and Demo Project Enhanced KeyValueStore with Query Caching and Demo Integration Jan 7, 2025
@GoogolC

GoogolC commented Jan 7, 2025 via email

Copy link
Copy Markdown
Author

@GoogolC

GoogolC commented Jan 7, 2025

Copy link
Copy Markdown
Author

Great PR. but, in fact, Lynx does not need a storage layer. If used as an adapter, it probably needs better designing, and more testing.

I have addressed the feedback by transforming KeyValueStore into a standalone demo project, better aligning with Lynx's architecture. This update includes restructuring the code, enhancing functionality with query caching, adding comprehensive unit tests, and providing a practical demo application to showcase its usage in real-world scenarios.
Please let me know if further refinements are required. Thank you for your valuable feedback!

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.

3 participants