# ca-tango-db-cache-mgr ## Installation ### Dependencies #### hiredis Either install from package manager or > git clone https://github.com/redis/hiredis.git > cd hiredis > mkdir build && cd build > cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/hiredis > make -j9 && sudo make install #### redis-plus-plus > git clone https://github.com/sewenew/redis-plus-plus > cd redis-plus-plus > mkdir build && cd build If redis has been manually installed in /usr/local/hiredis, then execute > cmake .. -DCMAKE_INSTALL_PREFIX=/opt/redis-plus-plus -DCMAKE_PREFIX_PATH=/opt/hiredis -DHIREDIS_HEADER=/opt/redis-plus-plus/include otherwise the options -DCMAKE_PREFIX_PATH and HIREDIS_HEADER is not necessary. We experienced that CMAKE_PREFIX_PATH is not enough to let redis plus plus include hiredis files correctly, and we need to add also -DHIREDIS_HEADER. > make -j9 > sudo make install ### service Installation Assuming the paths mentioned above were used to install hiredis and redis-plus-plus: > git clone https://gitlab.elettra.eu/puma/server/ca-tango-db-cache-mgr Adjust PKG_CONFIG_PATH according to the caserver-lib, hiredis, redis-plus-plus, cumbia-libs installation paths. For example: > export PKG_CONFIG_PATH=/opt/caserver-lib/lib/pkgconfig:/opt/hiredis/lib/pkgconfig:/opt/redis-plus-plus/lib/pkgconfig:$PKG_CONFIG_PATH *nlohmann-json* dependency is also required. You can place a copy in the *subprojects* directory if the package is not installed system-wide ### request syntax #### Subscribe to the attribute configuration change event and cache the configuration Source *test/device/1/double_scalar* > curl http://woody.elettra.eu:9296 -d $'{"srcs":[{"src":"test/device/1/double_scalar"}]}' Three sources: > curl -v http://taeyang.elettra.eu:9296 -d $'{"srcs":[{"src":"test/device/1/double_scalar"},{"src":"test/device/1/long_scalar"},{"src":"test/device/1/short_scalar"}]}' The first source will be processed immediately, the others according to the ``` ca-tango-db-cache-mgr:subscribe-rate ``` option in the configuration file (subscribe rate per second: default: two subscriptions per second) ##### Expected reply ```json {"msg":"ok","pos":0,"queue-cnt":3,"scheduled-cnt":3} ``` #### List the subscribed sources (method: "l") > curl -v http://taeyang.elettra.eu:9296 -d $'{"method":"l"}' ##### Expected reply ```json {"srcs":[{"src":"test/device/1/double_scalar"},{"src":"test/device/1/long_scalar"},{"src":"test/device/1/short_scalar"}]} ``` #### Process immediately all the queued sources (method "p") If you want to subscribe immediately all the sources in the queue regardless the maximum rate per second specified in the configuration: > curl http://taeyang.elettra.eu:9296 -d $'{"method":"p"}' ##### Expected reply ```json { "count": 2, "srcs": [ { "msg": "ok", "src": "test/device/1/long_scalar" }, { "msg": "ok", "src": "test/device/1/short_scalar" } ] } ``` #### Unsubscribe a set of sources (method: "u") Unsubscribe *double_scalar* and *long_scalar* from *test/device/1*: > curl -v http://taeyang.elettra.eu:9296 -d $'{"method":"u", "srcs":[{"src":"test/device/1/double_scalar"},{"src":"test/device/1/long_scalar"}]}' #### Expected reply If the two sources were being monitored: ```json {"count":2,"method":"u","removed":2,"srcs":[{"msg":"ok","src":"test/device/1/double_scalar"},{"msg":"ok","src":"test/device/1/long_scalar"}]} ``` In case of error (let's remove the two sources above twice): ```json {"count":2,"method":"u","removed":0,"srcs":[{"msg":"attribute double_scalar not found (devicetest/device/1)","src":"test/device/1/double_scalar"},{"msg":"attribute long_scalar not found (devicetest/device/1)","src":"test/device/1/long_scalar"}]} ``` #### Read the saved configuration for a set of sources (method:"r") This method can be useful to measure the time it takes to retrieve the configuration from the cache. It can be compared with the time taken to query the Tango Database directly to get the same piece of information.