<a id="how-to-cache-content-with-openstack-swift"></a>

# How to cache content with OpenStack/Swift storage

Sometimes it is desirable to cache Swift storage objects inside the charm for faster processing and reducing the number of requests to the [Swift](https://docs.openstack.org/swift/latest/) server. This also allows you to have a different hostname than the one from the Swift service.

This guide will demonstrate how to deploy this charm along with OpenStack/Swift storage.

**What you’ll need**:

* OpenStack instance and credentials. If you don’t have any credentials check [here](https://docs.openstack.org/zh_CN/user-guide/common/cli-set-environment-variables-using-openstack-rc.html) for more information.
* The content-cache-k8s charm deployed as `content-cache-k8s`.

First, connect to your OpenStack instance with your credentials, sourcing an .rc file:

```default
source myfile.rc

```

The OpenStack container you are going to work with has to be globally readable. check that property:

```default
swift stat <container_name>

```

And if it’s not globally readable yet, change that with:

```default
swift post <container_name> --read-acl ".r:*"

```

Then list all the objects on the OpenStack container in debug mode and get the URL of the Swift connection:

```default
openstack object list <container_name> -vv 2>&1 | grep "^REQ: curl" | grep AUTH | cut -d'"' -f2 | cut -d'?' -f1

```

After obtaining the URL, configure the charm to use that URL as our charm’s backend:

```default
juju config content-cache-k8s backend="http://<swift_conn_url>"

```

Once configured, you can use Swift commands to push or download objects. More details about Swift commands [here](https://docs.openstack.org/ocata/cli-reference/swift.html)

You can check everything is working by executing

```default
curl <swift connection url>

```

And also add a relation to the nginx-ingress-integrator charm:

```default
juju deploy nginx-ingress-integrator

```

If your cluster has [RBAC](https://kubernetes.io/docs/reference/access-authn-authz/rbac/) enabled, you’ll be prompted to run the following:

```default
juju trust nginx-ingress-integrator --scope cluster

```

The deployed application name will need to resolve to the IP of your ingress controller. A great way of testing this is to upload an index.html file into the OpenStack container and confirm that that content is reachable when they browse to this URL now.
