ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
2.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Lesser General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #define CPPCMS_SOURCE
  20. #include "cache_pool.h"
  21. #include "cache_storage.h"
  22. #include "base_cache.h"
  23. #include "cppcms_error.h"
  24. #include "cache_over_ip.h"
  25. #include "json.h"
  26. namespace cppcms {
  27. struct cache_pool::data {
  28. intrusive_ptr<impl::base_cache> module;
  29. };
  30. cache_pool::cache_pool(json::value const &settings) :
  31. d(new data())
  32. {
  33. std::string type = settings.get("cache.backend","none");
  34. if(type=="thread_shared") {
  35. if(settings.get("service.worker_processes",0)>1)
  36. throw cppcms_error(
  37. "Can't use `thread_shared' backend with more then one process ether set "
  38. "service.worker_processes to 0 or 1 or use cache.backend=\"process_shared\"");
  39. unsigned items = settings.get("cache.limit",64);
  40. d->module=impl::thread_cache_factory(items);
  41. }
  42. else if(type=="process_shared") {
  43. #ifdef CPPCMS_WIN32
  44. throw cppcms_error("The 'process_shared' backend is not supported under MS Windows and Cygwin platforms");
  45. #else
  46. size_t memory = settings.get("cache.memory",16384) * 1024;
  47. if(memory < 65536)
  48. throw cppcms_error("'process_shared' cache backend requires at least 64 KB of cache memory: cache.memory >= 64");
  49. d->module=impl::process_cache_factory(memory);
  50. #endif
  51. }
  52. else if(type != "none" ) {
  53. throw cppcms_error("Unsupported cache backend `" + type + "'");
  54. }
  55. if(settings.find("cache.tcp").type()==json::is_object) {
  56. std::vector<std::string> ips=settings.get<std::vector<std::string> >("cache.tcp.ips");
  57. std::vector<int> ports = settings.get<std::vector<int> >("cache.tcp.ports");
  58. if(ips.empty() || ports.empty() || ips.size()!=ports.size()) {
  59. throw cppcms_error("Invalid settings in cache.tcp.ports or cache.tcp.ips");
  60. }
  61. intrusive_ptr<impl::base_cache> l1=d->module;
  62. d->module=impl::tcp_cache_factory(ips,ports,l1);
  63. }
  64. }
  65. cache_pool::~cache_pool()
  66. {
  67. }
  68. intrusive_ptr<impl::base_cache> cache_pool::get()
  69. {
  70. return d->module;
  71. }
  72. } // cppcms