simple_dns_cache.h 674 B

1234567891011121314151617181920212223242526272829303132
  1. #pragma once
  2. #include <map>
  3. #include <memory>
  4. #include <string>
  5. #include "Poco/Net/DNS.h"
  6. #include "Poco/Net/HostEntry.h"
  7. #include "lru_cache.h"
  8. namespace qcloud_cos {
  9. struct HostEntryCache {
  10. Poco::Net::HostEntry host_entry;
  11. time_t cache_ts;
  12. };
  13. class SimpleDnsCache {
  14. public:
  15. using SharedLruCache = std::shared_ptr<LruCache<std::string, HostEntryCache>>;
  16. SimpleDnsCache(unsigned max_size, unsigned expire_seconds);
  17. ~SimpleDnsCache();
  18. // resolve host
  19. std::string Resolve(const std::string& host);
  20. bool Exist(const std::string& host);
  21. private:
  22. unsigned m_max_size;
  23. unsigned m_expire_seconds;
  24. SharedLruCache m_cache;
  25. };
  26. } // namespace qcloud_cos