Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Punjitha (algotyrnt)
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

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

The copyright holder is listed as "Punjitha (algotyrnt)" which appears to differ from the original author attribution "Punjitha Bandara" found in the original source files. Consider whether the copyright holder should be "Punjitha Bandara" to maintain consistency with the original author attribution, or if this shortened form is intentional.

Suggested change
Copyright (c) 2026 Punjitha (algotyrnt)
Copyright (c) 2026 Punjitha Bandara

Copilot uses AI. Check for mistakes.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ Cache0/
├── .github/ # The CI workflow
└── README.md # Readme File
```
## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
15 changes: 7 additions & 8 deletions include/cache0.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//
// cache0.hpp
// cache0
//
// Created by Punjitha Bandara on 2026-01-19.
//
/*
* Cache0 - A lightweight C++ Key-Value Store
* Copyright (c) 2026 Punjitha (algotyrnt)
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

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

The copyright header uses "Punjitha (algotyrnt)" which differs from the "Created by Punjitha Bandara" attribution in the original file. Consider whether the copyright holder should be "Punjitha Bandara" to maintain consistency with the original author attribution, or if the shortened form is intentional.

Suggested change
* Copyright (c) 2026 Punjitha (algotyrnt)
* Copyright (c) 2026 Punjitha Bandara

Copilot uses AI. Check for mistakes.
* Licensed under the MIT License.
*/

#ifndef CACHE0_HPP
#define CACHE0_HPP
Expand All @@ -17,13 +16,13 @@ class Cache0 {
private:
std::unordered_map<std::string, std::string> store;
const std::string filename = "cache0.db";

void load();
void save();
public:
Cache0(); // Constructor (Loads data)
~Cache0(); // Destructor (Saves data)

void put(const std::string& key, const std::string& value);
std::optional<std::string> get(const std::string& key);
bool remove(const std::string& key);
Expand Down
15 changes: 7 additions & 8 deletions src/cache0.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//
// cache0.cpp
// cache0
//
// Created by Punjitha Bandara on 2026-01-19.
//
/*
* Cache0 - A lightweight C++ Key-Value Store
* Copyright (c) 2026 Punjitha (algotyrnt)
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

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

The copyright header uses "Punjitha (algotyrnt)" which differs from the "Created by Punjitha Bandara" attribution in the original file. Consider whether the copyright holder should be "Punjitha Bandara" to maintain consistency with the original author attribution, or if the shortened form is intentional.

Suggested change
* Copyright (c) 2026 Punjitha (algotyrnt)
* Copyright (c) 2026 Punjitha Bandara

Copilot uses AI. Check for mistakes.
* Licensed under the MIT License.
*/

#include <iostream>
#include "../include/cache0.hpp"
Expand Down Expand Up @@ -33,7 +32,7 @@ bool Cache0::remove(const std::string& key) {

void Cache0::save() {
std::ofstream file(filename);

if (file.is_open()) {
for (const auto& pair : store) {
file << pair.first << "=" << pair.second << std::endl;
Expand All @@ -52,7 +51,7 @@ void Cache0::load() {
if (file.is_open()) {
while (std::getline(file, line)) {
size_t delimiterPos = line.find('=');

if (delimiterPos != std::string::npos) {
std::string key = line.substr(0, delimiterPos);
std::string value = line.substr(delimiterPos + 1);
Expand Down
19 changes: 9 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
//
// main.cpp
// cache0
//
// Created by Punjitha Bandara on 2026-01-19.
//
/*
* Cache0 - A lightweight C++ Key-Value Store
* Copyright (c) 2026 Punjitha (algotyrnt)
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

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

The copyright header uses "Punjitha (algotyrnt)" which differs from the "Created by Punjitha Bandara" attribution in the original file. Consider whether the copyright holder should be "Punjitha Bandara" to maintain consistency with the original author attribution, or if the shortened form is intentional.

Suggested change
* Copyright (c) 2026 Punjitha (algotyrnt)
* Copyright (c) 2026 Punjitha Bandara

Copilot uses AI. Check for mistakes.
* Licensed under the MIT License.
*/

#include <iostream>
#include "../include/cache0.hpp"

int main() {
std::cout << "[cache0] Initializing..." << std::endl;

Cache0 db;

db.put("user_id", "1024");

auto result = db.get("user_id");
if (result) {
std::cout << "[cache0] Found: " << *result << std::endl;
}

return 0;
}
25 changes: 12 additions & 13 deletions test/test_cache0.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//
// test_cache0.cpp
// cache0
//
// Created by Punjitha Bandara on 2026-01-20.
//
/*
* Cache0 - A lightweight C++ Key-Value Store
* Copyright (c) 2026 Punjitha (algotyrnt)
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

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

The copyright header uses "Punjitha (algotyrnt)" which differs from the "Created by Punjitha Bandara" attribution in the original file. Consider whether the copyright holder should be "Punjitha Bandara" to maintain consistency with the original author attribution, or if the shortened form is intentional.

Suggested change
* Copyright (c) 2026 Punjitha (algotyrnt)
* Copyright (c) 2026 Punjitha Bandara

Copilot uses AI. Check for mistakes.
* Licensed under the MIT License.
*/

#include <iostream>
#include <cassert>
Expand All @@ -17,24 +16,24 @@ void pass(const std::string& name) {
void test_basic_operations() {
{
Cache0 db;

// 1. Test PUT and GET
db.put("test_key", "123");
auto val = db.get("test_key");
assert(val.has_value() && "Key should exist");
assert(*val == "123" && "Value should be 123");

// 2. Test UPDATE (Overwrite)
db.put("test_key", "456");
val = db.get("test_key");
assert(*val == "456" && "Value should be updated to 456");

// 3. Test REMOVE
db.remove("test_key");
val = db.get("test_key");
assert(!val.has_value() && "Key should be deleted");
}

pass("Basic Operations");
}

Expand All @@ -50,16 +49,16 @@ void test_persistence() {
assert(val.has_value() && "Data should survive restart");
assert(*val == "alive" && "Value should be preserved");
}

pass("Persistence (Save/Load)");
}

int main() {
std::cout << "Running cache0 Tests..." << std::endl;

test_basic_operations();
test_persistence();

std::cout << "All tests passed successfully!" << std::endl;
return 0;
}