Field to count the number of objects in relation

Hi all. I have been reading about CounterCache behavior, but it is not useful for me (“main” object is not edited frequently, and related objects are generated by a background process). I have an entity, that has a hasMany relation, and I want to have a field to show the number of objects in that relation. Can this be done using a virtual field? Is there any other approach? Thanks!

It’s not clear to me why the background process wouldn’t be able to update the counter cache.