MDL-41106 Cleaning up expired elements in session cache store

- Always make sure the elements in cache are sorted so we need to remove only elements in the beginning of array
- Remove expired elements from session store to free memory
- Minor bug fixes
MDL-41106 cache: tidied up several elements
MDL-41106 Test not only cache store but appropriate cache class as well