APIs for managing cache and cache group

You can use the following APIs to manage cache and cache group.

Note

LoadOne, LoadGroup and LoadAll can work no matter the caches are stored in the file or in the database; the other APIs can only work when the caches are stored in the database. See Storing database connections in the database for how to store the database connections in a database (instead of the default file).

Syntax

Description

/api/Connection/LoadOne/{cacheGroup}/{cacheName}

Loads the configuration of a cache.

/api/Connection/LoadGroup/{cacheGroup}

Loads the configuration of all caches in a cache group.

/api/Connection/LoadAll

Loads the configuration of all caches in all cache groups.

/api/Connection/AddOne/{cacheGroup}

Adds a cache and configuration.

/api/Connection/RemoveOne/{cacheGroup}/{cacheName}

Removes a cache and configuration.

/api/Connection/AddGroup/{cacheGroup}/{copyFrom}

Adds a cache group by copying from another cache group.

/api/Connection/RemoveGroup/{cacheGroup}

Removes a cache group (and all caches in it).

/api/Connection/AddRange/{cacheGroup}

Adds more than one cache at a time.

/api/Connection/Edit/{cacheGroup}

Edits a cache.


LoadOne

Loads a cache.

Syntax: GET /api/Connection/LoadOne/{cacheGroup}/{cacheName}

{cacheGroup} indicates the cache group name, for example, Default.

{cacheName} indicates the cache to be loaded, for example, Sales.

PowerScript code example:

Integer li_rc
String ls_body 
httpclient  lhc_client
lhc_client = create httpclient

lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true)

li_rc  = lhc_client.sendrequest( "GET", "http://172.25.100.32:5000/api/Connection/LoadOne/Default/Sales")
if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then
 lhc_client.getresponsebody(ls_body)
end if

When successful, it returns the response status code 200 and the following response body. View here for details about the parameters in the response body.

When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).

{
  "cacheName": "string",
  "configuration": {
    "connectionType": 0,
    "host": "string",
    "port": 0,
    "odbcName": "string",
    "odbcDriver": "string",
    "userID": "string",
    "password": "string",
    "database": "string",
    "enablePooling": true,
    "minPoolSize": 0,
    "maxPoolSize": 0,
    "connectionLifetime": 0,
    "connectionTimeout": 0,
    "commandTimeout": 0,
    "otherOptions": "string",
    "securityOptions": "string",
    "dynamicConnection": true
  }
}

LoadGroup

Loads all caches in a cache group.

Syntax: GET /api/Connection/LoadGroup/{cacheGroup}

{cacheGroup} indicates the cache group to be loaded, for example, Default.

PowerScript code example:

Integer li_rc
String ls_body 
httpclient  lhc_client
lhc_client = create httpclient

lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true)

li_rc  = lhc_client.sendrequest( "GET", "http://172.25.100.32:5000/api/Connection/LoadGroup/Default")
if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then
 lhc_client.getresponsebody(ls_body)
end if

When successful, it returns the response status code 200 and the following response body. View here for details about the parameters in the response body.

When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).

[
  {
    "cacheName": "string",
    "configuration": {
      "connectionType": 0,
      "host": "string",
      "port": 0,
      "odbcName": "string",
      "odbcDriver": "string",
      "userID": "string",
      "password": "string",
      "database": "string",
      "enablePooling": true,
      "minPoolSize": 0,
      "maxPoolSize": 0,
      "connectionLifetime": 0,
      "connectionTimeout": 0,
      "commandTimeout": 0,
      "otherOptions": "string",
      "securityOptions": "string",
      "dynamicConnection": true
    }
  }
  {
    "cacheName": "string",
    ...
  }
]

LoadAll

Loads all cache groups (and caches in it).

Syntax: GET /api/Connection/LoadAll

PowerScript code example:

Integer li_rc
String ls_body 
httpclient  lhc_client
lhc_client = create httpclient

lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true)

li_rc  = lhc_client.sendrequest( "GET", "http://172.25.100.32:5000/api/Connection/LoadAll")
if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then
 lhc_client.getresponsebody(ls_body)
end if

When successful, it returns the response status code 200 and the following response body. View here for details about the parameters in the response body.

When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).

[
  {
    "cacheGroup": "string",
    "items": [
      {
        "cacheName": "string",
        "configuration": {
          "connectionType": 0,
          "host": "string",
          "port": 0,
          "odbcName": "string",
          "odbcDriver": "string",
          "userID": "string",
          "password": "string",
          "database": "string",
          "enablePooling": true,
          "minPoolSize": 0,
          "maxPoolSize": 0,
          "connectionLifetime": 0,
          "connectionTimeout": 0,
          "commandTimeout": 0,
          "otherOptions": "string",
          "securityOptions": "string",
          "dynamicConnection": true
        }
      }
    ]
  }
  {
    "cacheGroup": "string",
    ...
  }
]

AddOne

Adds a cache.

Syntax: POST /api/Connection/AddOne/{cacheGroup}

{cacheGroup} indicates the cache group where the cache will be added, for example, Default.

PowerScript code example:

For details about the parameters in the JSON string, view here.

Integer li_rc
String ls_body , ls_json
httpclient  lhc_client
lhc_client = create httpclient

lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true)

ls_json='{"cachename":"C1","configuration":{ "ConnectionType":0,"host":"172.168.13.1","port":1433,"userid":"sa","password":"sqltest","database":"appeonunittest","enablepooling":1,"minpoolsize":0,"maxpoolsize":100,"connectiontimeout":30,"commandtimeout":60,"DynamicConnection":0,"otheroptions":"","connectionlifetime":30,"securityOptions":"encrypt=false"}}'

li_rc  = lhc_client.sendrequest( "Post", "http://172.25.100.32:5000/api/Connection/AddOne/Default", ls_json)
if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then
 lhc_client.getresponsebody(ls_body)
end if

When successful, it returns the response status code 200 and the following response body:

When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).

{
  "isSucceeded": true,
  "errorMessage": "string"
}

AddRange

Adds more than one cache at a time.

Syntax: POST /api/Connection/AddRange/{cacheGroup}

{cacheGroup} indicates the cache group where the cache will be added, for example, Default.

PowerScript code example:

For details about the parameters in the JSON string, view here.

Integer li_rc
String ls_body , ls_json
httpclient  lhc_client
lhc_client = create httpclient

lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true)

ls_json='[{"cachename":"C11","configuration":{"ConnectionType":0,"host":"172.168.13.1","port":1433,"userid":"sa","password":"sqltest","database":"appeonunittest","enablepooling":1,"minpoolsize":0,"maxpoolsize":100,"connectiontimeout":30,"commandtimeout":60,"DynamicConnection":0,"otheroptions":"","connectionlifetime":30,"securityOptions":"encrypt=false"}},{"cachename":"C12","configuration":{"ConnectionType":0,"host":"172.168.13.1","port":1433,"userid":"sa","password":"sqltest","database":"appeonunittest","enablepooling":1,"minpoolsize":0,"maxpoolsize":100,"connectiontimeout":30,"commandtimeout":60,"DynamicConnection":0,"otheroptions":"","connectionlifetime":30,"securityOptions":"encrypt=false"}}]'

li_rc  = lhc_client.sendrequest( "Post", "http://172.25.100.32:5000/api/Connection/AddRange/NewCacheGroup", ls_json)
if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then
 lhc_client.getresponsebody(ls_body)
end if

When successful, it returns the response status code 200 and the following response body:

When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).

{
  "isSucceeded": true,
  "errorMessage": "string"
}

RemoveOne

Removes a cache.

Syntax: POST /api/Connection/RemoveOne/{cacheGroup}/{cacheName}

{cacheGroup} indicates the cache group name, for example, Default.

{cacheName} indicates the cache to be removed, for example, Sales.

PowerScript code example:

Integer li_rc
String ls_body 
httpclient  lhc_client
lhc_client = create httpclient

lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true)

li_rc  = lhc_client.sendrequest( "Post", "http://172.25.100.32:5000/api/Connection/RemoveOne/Default/C1")
if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then
 lhc_client.getresponsebody(ls_body)
end if

When successful, it returns the response status code 200 and the following response body:

When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).

{
  "isSucceeded": true,
  "errorMessage": "string"
}

Edit

Edits a cache.

Syntax: POST /api/Connection/Edit/{cacheGroup}

{cacheGroup} indicates the cache group where the cache will be modified, for example, Default.

PowerScript code example:

For details about the parameters in the JSON string, view here.

Integer li_rc
String ls_body , ls_json
httpclient  lhc_client
lhc_client = create httpclient

lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true)

ls_json='{"cachename":"C2","configuration":{"ConnectionType":0,"host":"172.168.13.100","port":1433,"userid":"sa1","password":"sqltest","database":"appeonunittest","enablepooling":1,"minpoolsize":10,"maxpoolsize":50,"connectiontimeout":30,"commandtimeout":60,"DynamicConnection":0,"otheroptions":"","connectionlifetime":30,"securityOptions":"encrypt=false"}}'

li_rc  = lhc_client.sendrequest( "Post", "http://172.25.100.32:5000/api/Connection/Edit/Default", ls_json)
if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then
 lhc_client.getresponsebody(ls_body)
end if

When successful, it returns the response status code 200 and the following response body:

When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).

{
  "isSucceeded": true,
  "errorMessage": "string"
}

AddGroup

Adds a cache group by copying from another cache group.

Syntax: POST /api/Connection/AddGroup/{cacheGroup}/{copyFrom}

{cacheGroup} indicates the name of the new cache group, for example, NewGroup.

{copyFrom} indicates the cache group to be copied from, for example, Default.

PowerScript code example:

Integer li_rc
String ls_body 
httpclient  lhc_client
lhc_client = create httpclient

lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true)

li_rc  = lhc_client.sendrequest( "Post", "http://172.25.100.32:5000/api/Connection/AddGroup/NewGroup/Default")
if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then
 lhc_client.getresponsebody(ls_body)
end if

When successful, it returns the response status code 200 and the following response body:

When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).

{
  "isSucceeded": true,
  "errorMessage": "string"
}

RemoveGroup

Removes a cache group (and all caches in it).

Syntax: POST /api/Connection/RemoveGroup/{cacheGroup}

{cacheGroup} indicates the cache group to be removed, for example, Group1.

PowerScript code example:

Integer li_rc
String ls_body 
httpclient  lhc_client
lhc_client = create httpclient

lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true)

li_rc  = lhc_client.sendrequest( "Post", "http://172.25.100.32:5000/api/Connection/RemoveGroup/NewGroup")
if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then
 lhc_client.getresponsebody(ls_body)
end if

When successful, it returns the response status code 200 and the following response body:

When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).

{
  "isSucceeded": true,
  "errorMessage": "string"
}