database: automatically create missing cache dir

On some systems the `/var/` dir is mounted in a tmpfs which is reseted
after each reboot. For that reason no post-install script can handle the
creation of the cache dir at `/var/cache/apk`.

Check on database opnening if the folder is available, if not create it.
Fixes #10715

Signed-off-by: Paul Spooren <mail@aparcar.org>
2 jobs for master in 40 seconds (queued for 1 second)
Status Job ID Name Coverage
  Test
passed #222811
x86_64 docker-alpine
test:alpine

00:00:33

passed #222812
x86_64 docker-alpine
test:debian

00:00:39