2019-01-06 12:52:55 -05:00
|
|
|
/*
|
|
|
|
|
ISC License
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link>
|
|
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-02-15 19:50:54 -06:00
|
|
|
#include "nonstd/optional.hpp"
|
2019-01-06 12:52:55 -05:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
#include <cstdint>
|
2019-01-06 12:52:55 -05:00
|
|
|
#include <string>
|
2024-02-15 18:11:59 -06:00
|
|
|
#include <unordered_map>
|
2019-01-06 12:52:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PolicyCache
|
|
|
|
|
{
|
2024-02-15 19:53:16 -06:00
|
|
|
public:
|
|
|
|
|
typedef std::unordered_map<std::string,std::string> Map;
|
|
|
|
|
|
2019-01-06 12:52:55 -05:00
|
|
|
public:
|
2024-02-15 19:50:54 -06:00
|
|
|
PolicyCache();
|
2019-01-06 12:52:55 -05:00
|
|
|
|
|
|
|
|
public:
|
2024-02-15 19:54:10 -06:00
|
|
|
void
|
2024-02-15 19:53:16 -06:00
|
|
|
insert(std::string const &key_,
|
|
|
|
|
std::string &val_)
|
|
|
|
|
{
|
2024-02-15 19:54:10 -06:00
|
|
|
_cache.insert({key_,val_});
|
2024-02-15 19:53:16 -06:00
|
|
|
}
|
|
|
|
|
|
2024-02-15 19:54:37 -06:00
|
|
|
void
|
|
|
|
|
erase(const char *key_)
|
|
|
|
|
{
|
|
|
|
|
_cache.erase(key_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-08-16 18:22:25 -04:00
|
|
|
void cleanup(const int prob = 1);
|
2019-01-06 12:52:55 -05:00
|
|
|
void clear(void);
|
|
|
|
|
|
|
|
|
|
private:
|
2024-02-15 19:48:28 -06:00
|
|
|
unsigned _max_size;
|
2024-02-15 19:45:44 -06:00
|
|
|
std::unordered_map<std::string,std::string> _cache;
|
2019-01-06 12:52:55 -05:00
|
|
|
};
|