<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Question about CloudCode API Hook and Global Property read costs &#x2F; usage count]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">We are planning to use a CloudCode script.RUN API Pre-hook to enforce a client app version gate.</p>
<p dir="auto">The flow is as follows:</p>
<ol>
<li>The client calls ScriptService.RunScript once.</li>
<li>A script.RUN Pre-hook runs our Pre_VersionGate CloudCode script.</li>
<li>Inside Pre_VersionGate, we call bridge.getGlobalProperty("VERSION_POLICY") once.</li>
<li>If the policy allows the request, the original CloudCode script runs.</li>
<li>If the policy blocks the request, the Pre-hook returns 403 and the original script does not run.</li>
</ol>
<p dir="auto">We would like to confirm how this affects usage and billing.</p>
<p dir="auto">Questions:</p>
<ol>
<li>Does the script.RUN Pre-hook execution count as a separate CloudCode execution or API count in addition to the original RunScript call?</li>
<li>Does bridge.getGlobalProperty("VERSION_POLICY") inside the Pre-hook count as an API call / usage count?</li>
<li>The CloudCode documentation mentions that the first 3 API calls are free and each call after that counts as 1/2. Does this rule apply to API Hook CloudCode scripts as well?</li>
<li>In the normal pass-through case, how is the usage count calculated?
<ul>
<li>1 client RunScript call</li>
<li>1 Pre-hook execution</li>
<li>1 getGlobalProperty call inside the Pre-hook</li>
<li>1 original CloudCode script execution</li>
</ul>
</li>
<li>In the blocked case, the original CloudCode script does not run. How is the usage count calculated in that case?</li>
<li>Could reading a Global Property on every script.RUN call become a performance or cost concern?</li>
<li>For a version policy that is read frequently but changed rarely, is there a recommended caching approach in BrainCloud?</li>
<li>Are there any Portal or usage report metrics where we can separately check the following?
<ul>
<li>API Hook execution count</li>
<li>CloudCode script execution count</li>
<li>CloudCode internal API call count</li>
<li>Global Property read count</li>
</ul>
</li>
</ol>
<p dir="auto">We do not have an exact traffic estimate yet, so for now we would like to understand how usage count is calculated for this structure.</p>
<p dir="auto">Thank you.</p>
]]></description><link>https://forums.getbraincloud.com/topic/363/question-about-cloudcode-api-hook-and-global-property-read-costs-usage-count</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 18:15:33 GMT</lastBuildDate><atom:link href="https://forums.getbraincloud.com/topic/363.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Jun 2026 07:11:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Question about CloudCode API Hook and Global Property read costs &#x2F; usage count on Mon, 08 Jun 2026 14:44:31 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="https://forums.getbraincloud.com/uid/571">@gyutaelee</a> ,</p>
<p dir="auto">Based on the current brainCloud's implementation, here are the answers to your questions:</p>
<p dir="auto">Q1: Does the Pre-hook count as a separate CloudCode execution / API count?**</p>
<p dir="auto">Yes. The Pre-hook counts as both a separate API call and a separate CloudCode script invocation. After running, the server publishes its own analytics event with operation "RUN_HOOK-Pre_VersionGate" that increments both counts.</p>
<p dir="auto">Q2: Does bridge.getGlobalProperty() count as an API call?**</p>
<p dir="auto">No. bridge.getGlobalProperty() is completely free. It reads directly from the cached Game object in memory and bypasses the API call tracking pipeline entirely.</p>
<p dir="auto">Q3: Does the "first 3 free, then 0.5 each" rule apply to hook CloudCode scripts?**</p>
<p dir="auto">Yes, the discount applies to internal calls from any script or hook within the session.</p>
<p dir="auto">Q4: Pass-through case: usage count breakdown</p>
<ul>
<li>Client calls script.RUN: +1 API call</li>
<li>Pre-hook executes: +1 API call</li>
<li>bridge.getGlobalProperty() inside hook: free</li>
<li>Original CloudCode script: +0 (covered by the original script.RUN request)</li>
</ul>
<p dir="auto">Total external API count: 2</p>
<p dir="auto">Q5: Blocked case: usage count breakdown</p>
<ul>
<li>Client calls script.RUN: +1 API call</li>
<li>Pre-hook executes: +1 API call</li>
<li>bridge.getGlobalProperty() inside hook: 0 (free)</li>
<li>Original script: +0 (does not run, server throws before invoking it when hook returns non-200)</li>
</ul>
<p dir="auto">Total external API count: 2</p>
<p dir="auto">The blocked case costs the same as pass-through from an API-count perspective. The only savings is that the original script's internal bridge.callAPI() calls are avoided.</p>
<p dir="auto">Q6: Could reading a Global Property on every script.RUN become a performance or cost concern?</p>
<p dir="auto">Performance: No. getGlobalProperty() reads from an in-memory cached Game object (ConcurrentHashMap per node) with no DB query or network call.</p>
<p dir="auto">Cost: The hook itself adds +1 API count to every script.RUN call that has the hook attached.</p>
<p dir="auto">Q7: Recommended caching approach for frequently-read, rarely-changed property?</p>
<p dir="auto">The cache is already in place, no additional caching needed. brainCloud stores the Game object (including all global properties) in an in-memory cache for each server node. Cross-node invalidation is handled automatically when a global property is updated in the portal. Using bridge.getGlobalProperty() is already the optimal pattern.</p>
<p dir="auto">Q8: Portal metrics: what can be broken down separately?</p>
<ul>
<li>API Hook execution count: Partially available. Hooks appear within the CC script invocation counter; no hook-only counter exists.</li>
<li>CloudCode script execution count: Available as CC Script Invocations, but includes hooks in the same counter.</li>
<li>CloudCode internal API call count: Available as CC API Calls in the Monitoring dashboard.</li>
<li>Global Property read count: Not tracked. No metric exists for this.</li>
</ul>
]]></description><link>https://forums.getbraincloud.com/post/1307</link><guid isPermaLink="true">https://forums.getbraincloud.com/post/1307</guid><dc:creator><![CDATA[JasonL]]></dc:creator><pubDate>Mon, 08 Jun 2026 14:44:31 GMT</pubDate></item></channel></rss>