def cache_by_group(view_instance, view_method, request, args, kwargs):
if request.user.is_anonymous():<EOL><INDENT>group = '<STR_LIT>'<EOL><DEDENT>elif request.user.is_superuser:<EOL><INDENT>group = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>group = request.user.groups.all().order_by('<STR_LIT>').first().name<EOL><DEDENT>except IndexError:<EOL><INDENT>group = '<STR_LIT>'<EOL><DEDENT><DEDENT>key = '<STR_LIT>' % (<EOL>view_instance.__class__.__name__,<EOL>request.META['<STR_LIT>'],<EOL>group,<EOL>request.accepted_media_type<EOL>)<EOL>return key<EOL>
Cache view response by media type and user group.
The cache_key is constructed this way: "{view_name:path.group.media_type}"
EG: "MenuList:/api/v1/menu/.public.application/json"
Possible groups are:
    * public
    * superuser
    * the rest are retrieved from DB (registered, community, trusted are the default ones)