Yep, you can do that!
That use case might be simple enough to do outside of Forge as well.
If you do use Forge, you'll get the security settings done for you - all you need to do is:
- Open up the memcached port 11211 to public connections (via firewall settings) OR (preferably) to the specific IP address of your servers accessing it (also via firewall settings)
- Ensure Memcached is listening on all networks, rather than just the localhost network. I think Forge does this by default:
$ ps aux | grep memcache
[stuff here] Sl Aug11 1:39 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 0.0.0.0
In that command on a Forge server of mine, we can see memcache is running on 0.0.0.0, which means "all networks". We can confirm this:
$ netstat -a | grep 11211
tcp 0 0 *:11211 *:* LISTEN
udp 0 0 *:11211 *:*
Great, so memcache is listening on port 1121 on all networks on port 11211 (*:11211) by default - that should be all set.
Consider this, however: Your use case will be making a network trip to the digital ocean server, which is NOT in the same data center (I'm assuming the shared hosting isn't based on digital ocean servers). You may not be saving response time unless the caching you use is saving you from expensive operations that would otherwise take longer than the network trip to the digital ocean box with memcached.