<% ' Cached Zabbix API wrapper for ALL supply levels (toner, ink, drums, maintenance kits, etc.) ' Simplified caching - no background refresh, minimal locking %> <% ' Cached function for all supply levels - simple 5-minute cache Function GetAllPrinterSuppliesCached(hostIP) On Error Resume Next Dim cacheKey, cacheTime, cacheAge, cachedData, forceRefresh cacheKey = "zabbix_all_supplies_" & hostIP ' Check if manual refresh was requested forceRefresh = (Request.QueryString("refresh") = "1" And Request.QueryString("ip") = hostIP) ' Check if valid cache exists (without locking) If Not forceRefresh Then cachedData = Application(cacheKey) cacheTime = Application(cacheKey & "_time") If Not IsEmpty(cachedData) And Not IsEmpty(cacheTime) Then cacheAge = DateDiff("n", cacheTime, Now()) If cacheAge < 5 Then ' Cache is fresh, return it GetAllPrinterSuppliesCached = cachedData Exit Function End If End If End If ' Cache miss or stale - fetch fresh data Dim zabbixConnected, pingStatus, suppliesJSON zabbixConnected = ZabbixLogin() If zabbixConnected = "1" Then pingStatus = GetPrinterPingStatus(hostIP) suppliesJSON = GetAllPrinterSupplies(hostIP) Else pingStatus = "-1" suppliesJSON = "" End If ' Store as array: [connected, pingStatus, suppliesJSON] Dim resultData(2) resultData(0) = zabbixConnected resultData(1) = pingStatus resultData(2) = suppliesJSON ' Cache the result (brief lock) Application.Lock Application(cacheKey) = resultData Application(cacheKey & "_time") = Now() Application.Unlock On Error Goto 0 GetAllPrinterSuppliesCached = resultData End Function %>