+
+ # Purge the module globals if necessary. If the cached value is
+ # non-nil and the globals weren't purged, return the cached
+ # value. Otherwise, call the block.
+ #
+ # Purge is only done in test mode.
+ def check_cache(cached)
+ if Rails.env != 'test'
+ return (cached || yield)
+ end
+ t = Rails.cache.fetch "CurrentApiClient.$system_globals_reset" do
+ Time.now.to_f
+ end
+ if t != $system_globals_reset
+ reset_system_globals(t)
+ yield
+ else
+ cached || yield
+ end
+ end
+
+ def reset_system_globals(t)
+ $system_globals_reset = t
+ $system_user = nil
+ $system_group = nil
+ $all_users_group = nil
+ $anonymous_group = nil
+ $anonymous_group_read_permission = nil
+ $anonymous_user = nil
+ $public_project_group = nil
+ $public_project_group_read_permission = nil
+ $anonymous_user_token_api_client = nil
+ $system_root_token_api_client = nil
+ $empty_collection = nil
+ end
+ module_function :reset_system_globals