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.
 
 
 
 
 
 

148 lines
3.1 KiB

  1. #include "cache_interface.h"
  2. #include "worker_thread.h"
  3. #include "global_config.h"
  4. #include <boost/iostreams/filtering_stream.hpp>
  5. #include <boost/iostreams/filter/gzip.hpp>
  6. #include <sstream>
  7. #include <iostream>
  8. #include "manager.h"
  9. namespace cppcms {
  10. using namespace std;
  11. void deflate(string const &text,ostream &stream,long level,long length)
  12. {
  13. using namespace boost::iostreams;
  14. gzip_params params;
  15. if(level!=-1){
  16. params.level=level;
  17. }
  18. filtering_ostream zstream;
  19. if(length!=-1){
  20. zstream.push(gzip_compressor(params,length));
  21. }
  22. else {
  23. zstream.push(gzip_compressor(params));
  24. }
  25. zstream.push(stream);
  26. zstream<<text;
  27. }
  28. string deflate(string const &text,long level,long length)
  29. {
  30. ostringstream sstream;
  31. deflate(text,sstream,level,length);
  32. return sstream.str();
  33. }
  34. bool cache_iface::fetch_page(string const &key)
  35. {
  36. if(!cms->caching_module) return false;
  37. string tmp;
  38. if(cms->caching_module->fetch_page(key,tmp,cms->gzip)) {
  39. cms->cout<<tmp;
  40. cms->gzip_done=true;
  41. return true;
  42. }
  43. return false;
  44. }
  45. void cache_iface::store_page(string const &key,time_t timeout)
  46. {
  47. if(!cms->caching_module) return;
  48. archive a;
  49. long level=cms->app.config.lval("gzip.level",-1);
  50. long length=cms->app.config.lval("gzip.buffer",-1);
  51. string tmp=cms->out_buf.str();
  52. string compr=deflate(tmp,level,length);
  53. a<<tmp<<compr;
  54. if(cms->gzip){
  55. cms->out_buf.str("");
  56. cms->cout<<compr;
  57. cms->gzip_done=true;
  58. }
  59. cms->caching_module->store(key,triggers,timeout,a);
  60. }
  61. void cache_iface::add_trigger(string const &t)
  62. {
  63. if(!cms->caching_module) return;
  64. triggers.insert(t);
  65. }
  66. void cache_iface::rise(string const &t)
  67. {
  68. if(!cms->caching_module) return;
  69. cms->caching_module->rise(t);
  70. }
  71. bool cache_iface::fetch_data(string const &key,serializable &data)
  72. {
  73. if(!cms->caching_module) return false;
  74. archive a;
  75. set<string> new_trig;
  76. if(cms->caching_module->fetch(key,a,new_trig)) {
  77. data.load(a);
  78. triggers.insert(new_trig.begin(),new_trig.end());
  79. return true;
  80. }
  81. return false;
  82. }
  83. void cache_iface::store_data(string const &key,serializable const &data,
  84. set<string> const &triggers,
  85. time_t timeout)
  86. {
  87. if(!cms->caching_module) return;
  88. archive a;
  89. data.save(a);
  90. this->triggers.insert(triggers.begin(),triggers.end());
  91. cms->caching_module->store(key,triggers,timeout,a);
  92. }
  93. bool cache_iface::fetch_frame(string const &key,string &result)
  94. {
  95. if(!cms->caching_module) return false;
  96. archive a;
  97. set<string> new_trig;
  98. if(cms->caching_module->fetch(key,a,new_trig)) {
  99. a>>result;
  100. triggers.insert(new_trig.begin(),new_trig.end());
  101. return true;
  102. }
  103. return false;
  104. }
  105. void cache_iface::store_frame(string const &key,string const &data,
  106. set<string> const &triggers,
  107. time_t timeout)
  108. {
  109. if(!cms->caching_module) return;
  110. archive a;
  111. a<<data;
  112. this->triggers.insert(triggers.begin(),triggers.end());
  113. cms->caching_module->store(key,triggers,timeout,a);
  114. }
  115. void cache_iface::clear()
  116. {
  117. if(cms->caching_module)
  118. cms->caching_module->clear();
  119. }
  120. bool cache_iface::stats(unsigned &k,unsigned &t)
  121. {
  122. if(!cms->caching_module)
  123. return false;
  124. cms->caching_module->stats(k,t);
  125. return true;
  126. }
  127. } // End of namespace cppcms