# xhttpcache **Repository Path**: fnet/xhttpcache ## Basic Information - **Project Name**: xhttpcache - **Description**: 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. - **Primary Language**: Unknown - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 16 - **Created**: 2016-09-29 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [![Author](https://img.shields.io/badge/author-@0xsky-blue.svg?style=flat)](http://www.0xsky.com/) [![Platform](https://img.shields.io/badge/platform-Linux,%20BSD,%20OS%20X,%20Windows-green.svg?style=flat)](https://github.com/0xsky/xhttpcache) [![NoSQL](https://img.shields.io/badge/db-NoSQL-pink.svg?tyle=flat)](https://github.com/0xsky/xhttpcache) [![License](https://img.shields.io/badge/license-GPL-yellow.svg?style=flat)](LICENSE) #What is xhttpcache? ([中文说明](README_cn.md)) 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](http://xhttpcache.0xsky.com/images/plans.png) ###Compilation and installation Compiler dependency Library: Need compiling and installing in advance ``` ``` build ``` wget --no-check-certificate https://github.com/0xsky/xhttpcache/archive/master.zip unzip master.zip cd xhttpcache-master make ``` ##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 ```bash [xsky@localhost xhttpcache]$ redis-cli -p 7379 127.0.0.1:7379> set test hello OK 127.0.0.1:7379> get test "hello" 127.0.0.1:7379> set test hello ex 1000 OK 127.0.0.1:7379> get test "hello" 127.0.0.1:7379> ttl test (integer) 988 127.0.0.1:7379> EXPIRE test 2000 (integer) 1 127.0.0.1:7379> ttl test (integer) 1998 127.0.0.1:7379> get test "hello" 127.0.0.1:7379> ``` ###Add image files to xhttpcache via the redis command ```bash redis-cli -p 7379 -x set getheadimg.jpg "$0}'|sh cd $data_dir redis-cli -h $redis_host -p $redis_port scan a z | while read line do echo $line bdir=`expr index $line "/"` file_dir=${line%/*} file_name=$line if [[ $bdir -gt 0 ]];then #echo 1 $bdir $file_dir $file_name mkdir -p $file_dir fi redis-cli -h $redis_host -p $redis_port get $line > $line done cd - else echo [ERROR] the dir $data_dir do not exist exit 0 fi ``` ###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. * [libevent](http://libevent.org/) * [libevhtp](https://github.com/ellzey/libevhtp) * [rocksdb](http://rocksdb.org/) * [ssdb](http://ssdb.io/) ###About the author * [xhttpcache websit](http://xhttpcache.0xsky.com/) * xhttpcache QQGroup: 195957781 * [xSky blog](http://www.0xsky.com/) * Email: guozhw@gmail.com