Many epidemiological studies assess the effects of time-dependent exposures, where both the exposure status and its intensity vary over time. One example that attracts public attention concerns pharmacoepidemiological studies of the adverse effects of medications. The analysis of such studies poses challenges for modeling the impact of complex time-dependent drug exposure, especially given the uncertainty about the way effects cumulate over time and about the etiological relevance of doses taken in different time periods. We present a flexible method for modeling cumulative effects of time-varying exposures, weighted by recency, represented by time-dependent covariates in the Cox proportional hazards model. The function that assigns weights to doses taken in the past is estimated using cubic regression splines. We validated the method in simulations and applied it to re-assess the association between exposure to a psychotropic drug and fall-related injuries in the elderly.