Those who surf the internet in middle age can cut their risk of dementia in later life by more than half, a study has shown.