Caste, to be more specific was your ancestry. It was determined by the patrilineal bloodline which you were born into. The son of a Brahmin was a Brahmin, the son of a Rajput was a Rajput. So on and so forth. In that context, it's still the case.
"Foreigners" or tribes or groups of people that were alien to the Indo-Aryans and their later descendants in the subcontinent, who disseminated and expanded their cultural sphere eventually Sanskritising most of the subcontinent, were perceived in a distinctly negative light by the Indo-Aryans and their descendants. In the Rig Veda the Indo-Aryans refer to IVC remnants as Mlecchas. "Unclean" or "low lying" might be close translations. But it can be seen as a term for othering non-Aryan ethno-lingual groups. Therefore, whatever the occupation or profession of a "foreigner" may be, they would be seen as Mlecchas. The othering of the non-Aryan and the necessity to discriminate against such groups was present in Indo-Aryan society since the early Rig Vedic period.
Ofc, this dynamic wasn't permanent, post-Vedic society followed a system of integration into the Brahminical fold, by a process known as "Sanskritization" under which groups and communities that were non-Vedic or "non-Hindu" (for convenience) would be assimilated into Hindu society, where "jatis" or subcastes and "Varnas" or caste categories, would be assigned to these groups based on the social, poltical and economic status of individuals and clans and communities. The prerequisite for this process of assimilation however, seems to have been Brahminical hegemony, which would explain why later Turkish and European arrivals in the subcontinent, weren't assimilated as compares to groups such as the Jats.
Interactions between "twice-born" Hindus and non-caste "foreigners" were highly caste and class specific. So much so that it is difficult to generalise for individual caste categories, let alone the entire traditional upper caste section of Hindu society. Brahmins, claiming ritual superiority in the caste hierarchy would perceive and interact with, Europeans based on their postion in society and that of the Englishman or Frenchman they interacted with. A Brahmin priest would be apprehensive of the latter, regardless. Meanwhile a soldier from the Oudh and Bhojpur regions recruited in the Bengal Army would be cordial and respectful towards his British officers. The sepoy would still however, eat meat butchered by a Brahmin, or prepare food himself. For Brahmin landlords, kings and gentry, cordial relations with British officers and residents would be the norm. Here, practicality would be prioritised over observance of caste restrictions and dinners, but even so, matrimonial relations with someone outside of one's caste group, let alone the entire caste structure, were a taboo, and a grave breach of the caste rules and restrictions. The degree to which these restriction would be abided by would again vary. Among the Brahmins, it may be assumed that these observances were of absolute priority. Among the ritually highest placed Kshatriya/Rajput lineages, such as the Suryavanshis, their observance would be likewise of paramount importance. The lower one went down the gradations of caste and ritual purity, the further loose and light these restrictions became. However, it would never be the case that they were simply thrown to the wind, since, to quote, Seton-Karr, W. S. (Walter Scott), 1822-1910. The Marquess Cornwallis and the consolidation of British rule (1898). pp. 194 :
There is nothing democratic in the various strata of Indian society. From its earliest traditions to its recent history it has been the sanctuary of privilege. Its tribes worship pomp and pageantry, and are reconciled to an apparent inequality, over which every man of talent and capacity hopes to triumph. It may be taken as an axiom that the general sense of the natives is in favour of marked gradations of rank, and of exemption from restraints and restrictions, while at the same time a value is set on impartial justice, inviolate good faith, and incorruptible integrity. Guilds and fraternities, associations of traders, community of interests between co-parcenary communities, are not democratic, but if anything oligarchical; and caste, in all its endless ramifications, is a symbol of honour and not a badge of disgrace.
Even among those subcaste of "twice-born" Hindus which would be considered at the bottom of their caste category's gradation of ritual purity, there would still be this sense of honour and identity associated with caste, hence, while variations would exist, the overall nature of these interactions would be varying degrees and numbers of restrictions, from highest among the ryot and priestly class, to relatively lowest among the nobility, which eventually underwent the process of adopting British ideas and pretensions of royalty.
There are also theories that this rigid caste barrier did not exist before the arrival of the British. Again, when the "British" arrived in the subcontinent is debatable. Individuals, groups and corporations, which would eventually, as the result of the formation of the Kingdom of Great Britain in 1707, be referred to as "British" were already present in the subcontinent since the early 1600s. But caste was rigid and entrenched since around 2000 years ago, at the very least, if not before.
The following papers shed light on caste endogamy and male driven mixing patterns in Indo-Aryan/Rig Vedic society. This exercise becomes necessary to do away with the notion that the rigid caste boundaries as we understand them, were a recent phenomenon.
Here's one by Narsimhan et. al.
Our analysis also provides a second line of evidence for a linkage between Steppe ancestry and Indo-European languages. Steppe ancestry enrichment in groups that view themselves as being of traditionally priestly status is striking as some of these groups including Brahmins are traditional custodians of literature composed in early Sanskrit. A possible explanation is that the influx of Central_Steppe_MLBA ancestry into South Asia in the mid-2nd millennium BCE created a meta-population with varied proportions of Steppe ancestry with people of more Steppe ancestry (or admixing less with Indus Periphery Cline groups) tending to be more strongly associated with Indo-European culture. Due to strong endogamy, which kept groups generally isolated from neighbors for thousands of years (7), some of this population substructure persists in South Asia among present-day custodians of Indo-European texts.
we found an extremely marked sex bias by comparing the different genetic systems. Maternal lineages primarily reflect earlier, pre-Holocene processes, and paternal lineages predominantly episodes within the last 10 ka. In particular, genetic influx from Central Asia in the Bronze Age was strongly male-driven, consistent with the patriarchal, patrilocal and patrilineal social structure attributed to the inferred pastoralist early Indo-European society. This was part of a much wider process of Indo-European expansion, with an ultimate source in the Pontic-Caspian region, which carried closely related Y-chromosome lineages, a smaller fraction of autosomal genome-wide variation and an even smaller fraction of mitogenomes across a vast swathe of Eurasia between 5 and 3.5 ka.
Lastly, from Who We Are and How We Got Here (2018), by David Reich and Eugenie Reich, pp. 143-144 :
To understand the extent to which the jatis corresponded to real genetic patterns, we examined the degree of differentiation of each jati from which we had data with all others based on differences in mutation frequencies. We found that the degree of differentiation was at least three times greater than that among European groups separated by similar geographic distances. This could not be explained by differences in ANI ancestry among groups, or differences in the region within India from which the population came, or differences in social status. Even comparing pairs of groups matched according to these criteria, we found that the degree of genetic differentiation among Indian groups was many times larger than that in Europe.
Around a third of Indian groups experienced population bottlenecks as strong or stronger than the ones that occurred among Finns or Ashkenazi Jews
To summarise, there is simply no way that such drastic genetic differentiation could be a product of the British, conquering most of India by 1858, and imposing rigid caste barriers upon the same society. They exited since millenia before.