title | slug | section | updated |
---|---|---|---|
Memcached (Object cache) |
memcached |
Services |
2021-06-03 |
Last updated 3rd June 2021
Memcached is a simple in-memory object store well-suited for application level caching.
See the Memcached for more information.
Both Memcached and Redis can be used for application caching. As a general rule, Memcached is simpler and thus more widely supported while Redis is more robust. Web PaaS recommends using Redis if possible but Memcached is fully supported if an application favors that cache service."
Grid |
---|
1.4 |
1.5 |
1.6 |
The format exposed in the $PLATFORM_RELATIONSHIPS
environment variable:
{
"service": "memcached16",
"ip": "169.254.34.86",
"hostname": "3sdm72jgaxge2b6aunxdlzxyea.memcached16.service._.eu-3.platformsh.site",
"cluster": "rjify4yjcwxaa-master-7rqtwti",
"host": "memcached.internal",
"rel": "memcached",
"scheme": "memcached",
"type": "memcached:1.6",
"port": 11211
}
In your .platform/services.yaml
:
cachemc:
type: memcached:1.6
Now add a relationship in your .platform.app.yaml
file:
relationships:
memcachedcache: "cachemc:memcached"
You will need to use
memcached
type when defining the service# .platform/services.yaml service_name: type: memcached:versionand the endpoint
memcached
when defining the relationship# .platform.app.yaml relationships: relationship_name: “service_name:memcached”Your
service_name
andrelationship_name
are defined by you, but we recommend making them distinct from each other.
If you are using PHP, configure the relationship and enable the PHP memcached extension in your .platform.app.yaml
. (Note that the memcached
extension requires igbinary
and msgpack
as well, but those will be enabled automatically.)
runtime:
extensions:
- memcached
For Python you will need to include a dependency for a Memcached library, either via your requirements.txt file or a global dependency. As a global dependency you would add the following to .platform.app.yaml
:
dependencies:
python:
python-memcached: '*'
You can then use the service in a configuration file of your application with something like:
[!tabs]
Go{!> web/web-paas/static/files/fetch/examples/golang/memcached !}Java
{!> web/web-paas/static/files/fetch/examples/java/memcached !}PHP
{!> web/web-paas/static/files/fetch/examples/php/memcached !}Python
{!> web/web-paas/static/files/fetch/examples/python/memcached !}