Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Add end-point for clearing cache.

Kishore Nallan8ff57108faad
diff --git a/include/core_api.h b/include/core_api.h
index 006d21b6..a283cc16 100644
--- a/include/core_api.h
+++ b/include/core_api.h
@@ -97,6 +97,8 @@ bool post_vote(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_
bool post_config(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res);
+bool post_clear_cache(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res);
+
// Misc helpers
void get_collections_for_auth(std::map<std::string, std::string> &req_params, const std::string &body,
diff --git a/src/core_api.cpp b/src/core_api.cpp
index adc80da1..43effbf9 100644
--- a/src/core_api.cpp
+++ b/src/core_api.cpp
@@ -1327,6 +1327,19 @@ bool post_config(const std::shared_ptr<http_req>& req, const std::shared_ptr<htt
return true;
}
+bool post_clear_cache(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res) {
+ {
+ std::unique_lock lock(mutex);
+ res_cache.clear();
+ }
+
+ nlohmann::json response;
+ response["success"] = true;
+ res->set_200(response.dump());
+
+ return true;
+}
+
bool get_synonyms(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res) {
CollectionManager & collectionManager = CollectionManager::get_instance();
auto collection = collectionManager.get_collection(req->params["collection"]);
diff --git a/src/main/typesense_server.cpp b/src/main/typesense_server.cpp
index db56a462..d70958b6 100644
--- a/src/main/typesense_server.cpp
+++ b/src/main/typesense_server.cpp
@@ -68,6 +68,7 @@ void master_server_routes() {
server->post("/operations/snapshot", post_snapshot, false, true);
server->post("/operations/vote", post_vote, false, false);
+ server->post("/operations/cache/clear", post_clear_cache, false, false);
server->post("/config", post_config, false, false);
}