Skip to content

Commit

Permalink
fix: Don't cache HTTP object stores as they maintain URL state (#15121)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Mar 18, 2024
1 parent ff85894 commit f0298a5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/polars-io/src/cloud/object_store_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub async fn build_object_store(
let cloud_location = CloudLocation::from_url(&parsed)?;

let key = url_to_key(&parsed);
let mut allow_cache = true;

{
let cache = OBJECT_STORE_CACHE.read().await;
Expand Down Expand Up @@ -93,11 +94,13 @@ pub async fn build_object_store(
return err_missing_feature("azure", &cloud_location.scheme);
},
CloudType::File => {
allow_cache = false;
let local = LocalFileSystem::new();
Ok::<_, PolarsError>(Arc::new(local) as Arc<dyn ObjectStore>)
},
CloudType::Http => {
{
allow_cache = false;
#[cfg(feature = "http")]
{
let store = object_store::http::HttpBuilder::new()
Expand All @@ -111,11 +114,13 @@ pub async fn build_object_store(
return err_missing_feature("http", &cloud_location.scheme);
},
}?;
let mut cache = OBJECT_STORE_CACHE.write().await;
// Clear the cache if we surpass a certain amount of buckets. Don't expect that to happen.
if cache.len() > 512 {
cache.clear()
if allow_cache {
let mut cache = OBJECT_STORE_CACHE.write().await;
// Clear the cache if we surpass a certain amount of buckets.
if cache.len() > 32 {
cache.clear()
}
cache.insert(key, store.clone());
}
cache.insert(key, store.clone());
Ok((cloud_location, store))
}

0 comments on commit f0298a5

Please sign in to comment.