Algorithms For Distributed Caching And Aggregation