ADC

Use Case: Caching User Privileges

In this use case, user privileges (“GOLD”, “SILVER”, and so on) must be retrieved from an external web service.

To achieve this use case, perform the following operations

创建一个HTTP callout获取用户的特权s from the external web service.

add policy httpcallout  [-IPAddress ] [-port ] [-vServer ] [-returnType ] [-httpMethod (GET | POST )] [-hostExpr ] [-urlStemExpr ] [-headers  ...] [-parameters  ...] [-bodyExpr ][-fullReqExpr ] [-scheme ( http | https )] [-resultExpr ] [-cacheForSecs ] [-comment ] add policy httpcallout get_user_privilege -ipaddress 10.217.193.84 -port 80 -returnType text -httpMethod GET -hostExpr '"/get_user_privilege"' -resultExpr 'http.res.body(5)' 

Store the privileges in a variable.

add ns variable  -type  [-scope ( global | transaction )][-ifFull ( undef | lru )] [-ifValueTooBig ( undef | truncate )][-ifNoValue ( undef | init )] [-init ] [-expires ] [-comment ] add ns variable user_privilege_map -type map(text(15),text(10),10000) -expires 1200 add ns assignment set_user_privilege -variable $user_privilege_map[client.ip.src] -set sys.http_callout(get_user_privilege) 

Create a policy to check if there is already a cached entry for the client’s IP address; if not, it calls the HTTP callout to set a map entry for the client.

add cmp policy  -rule  -resAction  add cmp policy set_user_privilege_pol -rule $user_privilege_map.valueExists(client.ip.src).not -resAction set_user_privilege> 

Create a policy that compresses if the cached privilege entry for the client is “GOLD”.

add cmp policy  -rule  -resAction  add cmp policy compress_if_gold_privilege_pol -rule '$user_privilege_map[client.ip.src].eq("GOLD")' -resAction compress 

Bind the compression policies globally.

bind cmp global  [-priority ] [-state (ENABLED | DISABLED )] [-gotoPriorityExpression ] [-type ] [-invoke ( ) ] bind cmp global set_user_privilege_pol -priority 10 NEXT bind cmp global compress_if_gold_privilege_pol -priority 20 END 
Use Case: Caching User Privileges