Fix problems with memcache and memcached session storage

Tracker #31453