aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/namespacecachestore.h
blob: 85f4150bf35a47fba7aa2d62a9aa38d62ce082b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include <zencore/logging.h>
#include <zencore/refcount.h>

#include <zenstore/gc.h>

#include <string>

namespace zen {

class ScrubContext;
class ZenCacheStore;
struct ZenCacheValue;

/** NamespaceCache Store
 */
class NamespaceCacheStore : public RefCounted, public GcStorage, public GcContributor
{
public:
	NamespaceCacheStore(std::filesystem::path BasePath, CasGc& Gc);
	~NamespaceCacheStore();

	bool Get(const std::string& Namespace, std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue);
	void Put(const std::string& Namespace, std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value);
	bool DropBucket(const std::string& Namespace, std::string_view Bucket);
	void Flush();
	void Scrub(ScrubContext& Ctx);

	spdlog::logger&				 Log() { return m_Log; }
	const std::filesystem::path& BasePath() const { return m_BasePath; }

	virtual void		  GatherReferences(GcContext& GcCtx) override;
	virtual void		  CollectGarbage(GcContext& GcCtx) override;
	virtual GcStorageSize StorageSize() const override;

private:
	std::vector<std::string>						FindExistingFolders() const;
	ZenCacheStore*									GetStore(const std::string& Namespace);
	std::vector<ZenCacheStore*>						GetAllStores() const;
	spdlog::logger&									m_Log;
	std::filesystem::path							m_BasePath;
	mutable RwLock									m_NamespacesLock;
	std::unordered_map<std::string, ZenCacheStore*> m_Namespaces;
};

}  // namespace zen