Watch 10 Star 27 Fork 16

xSky / xhttpcacheC++GPL-3.0

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Notice: Creating folder will generate an empty file .keep, because not support in Git

Author Platform NoSQL License

#What is xhttpcache? (中文说明) Xhttpcache is a HTTP static cache service, which is also NOSQL database as K-V storage supporting REDIS protocol interface as well as REST interface of HTTP protocol.

#What are the functions of xhttpcache?

  • Provision of caching services for HTTP data and support for binary data storage;
  • Realization of full K-V storage and permanent data storage (ROCKSDB);
  • Support for data timeout mechanism with Millisecond accuracy;
  • Implementation of the complete REDIS protocol interface with the SET/GET/DEL/EXIRE/TTL order for redis;
  • Implementation of the HTTP/HTTPS protocol interface as well as access via REST command;
  • Implementation of HTTP cache related protocol in support of eTage ,304 Not Modified and gzip compression for transmission content;
  • Data Adjunction/ modification / deletion directly with WEB background editor

###Graphic xhttpcache xhttpcache

###Compilation and installation

Compiler dependency Library: Need compiling and installing in advance


wget --no-check-certificate 
cd xhttpcache-master 

##Approaches: xhttpcache is designed as accelerated server for HTTP data: Data written to the xhttpcache by providing the write interface accessed directly through the browser. Meanwhile, reading and writing through redis` client(support a variety of languages) with the help of a redis protocol interface, which serves as a simple NOSQL databases; Established K-V data through a REDIS interface offering direct access via the HTTP interface in a browser

The usage of NOSQL database: establish the K-V data through the REDIS interface, visit the database through the HTTP interface in the browser

Access via HTTP interface There are two HTTP service port in xhttpcache configured in the configuration file. Httpd_frontend_port is an open visiting port with read-only requests while Httpd_backend_port is the back-end data ports supporting all the REST reading and writing requests (get/post/put/delete); Back-end data access can be set logining password;

###The samples under the redis command: The following example shows all the supported REDIS commands

    [xsky@localhost xhttpcache]$ redis-cli -p 7379> set test hello 
    OK> get test
    "hello"> set test hello ex 1000
    OK> get test
    "hello"> ttl test
    (integer) 988> EXPIRE test 2000
    (integer) 1> ttl test
    (integer) 1998> get test

###Add image files to xhttpcache via the redis command

redis-cli -p 7379 -x set getheadimg.jpg <getheadimg.jpg

###Bulk of data imports and exports Import bulk of disk file to the xhttpcache through the following script leading the files in the directory specified by the parameter into the xhttpcache.


redis_cmd="redis-cli -p 7379 -x set "
function batch_convert() {
    for file in `ls $1`
        if [ -d $1"/"$file ]
            batch_convert $1"/"$file
            #echo 33 $redis_cmd  ${key#*/}   $1"/"$file
            $redis_cmd ${key#*/} < $1"/"$file

batch_convert $1

The data in the xhttpcache can be exported to the disk in the form of a directory file by the following shell script,

# xHttpCache数据备份脚本
# By: xSky

    echo "++++++++++++++++++++++++++++++++++++++++++++++++++++" 
    echo "+ xHttpCache data export shell tools by:xSky       " 
    echo "+ usage:                                           " 
    echo "+ $0 data_dir redis_host redis_port                " 
    echo "++++++++++++++++++++++++++++++++++++++++++++++++++++" 

if [ $# -ne 3 ]; then
    exit 0

echo $data_dir $redis_host $redis_port

if [ -d $data_dir ];then
    #redis-cli -p 6579 scan a z | awk  '{print "redis-cli -p 6579 get "$0 " >"$0}'|sh
    cd $data_dir
    redis-cli -h $redis_host -p $redis_port scan a z | while read line
        echo $line 
        bdir=`expr index $line "/"`

        if [[ $bdir -gt 0 ]];then
            #echo 1 $bdir $file_dir $file_name
            mkdir -p $file_dir

        redis-cli -h $redis_host -p $redis_port get $line > $line

    cd -
    echo [ERROR] the dir $data_dir do not exist
    exit 0

###Characteristic description: xhttpcache can return the corresponding file suffix Content-Type judging the URI type visited by HTTP, which makes its HTTP interface a real WEB server. When accessed through the browser, the data will be displayed directly in the form of a page instead of the usual data interface. For example: for the address with the /test.htm form. When returning contents, the HTTP head returns: text/html Content-Type, which can be displayed in the form of HTML through the browser directly to the test.htm corresponding data content, For the key in the /test.jpg form, if the value content should be JPG image data, the normal display as a picture appears through the browser to access the /test.jpg. Besides, the background supports the previewing and uploading of the pictures. According to the above characteristics, it can be very easy to load all the static web site files to cache with full memory.

###Gratitude Be grateful of the following items. Ranking regardless.

###About the author

Comments ( 2 )

Sign in for post a comment


Xhttpcache is a HTTP static cache service, which is also NOSQL database as K-V storage supporting REDIS protocol interface as well as REST interface of HTTP protocol. spread retract
C++ and 4 more languages


No release

Gitee Metrics




load more
can not load any more