+/**
+ * @param File $img
+ * @param string $thumbName
+ * @param int $limit
+ * @return int|bool
+ */
+function wfThumbIsAttemptThrottled( File $img, $thumbName, $limit ) {
+ global $wgMemc;
+
+ return ( $wgMemc->get( wfThumbAttemptKey( $img, $thumbName ) ) >= $limit );
+}
+
+/**
+ * @param File $img
+ * @param string $thumbName
+ */
+function wfThumbIncrAttemptFailures( File $img, $thumbName ) {
+ global $wgMemc;
+
+ $key = wfThumbAttemptKey( $img, $thumbName );
+ if ( !$wgMemc->incr( $key, 1 ) ) {
+ if ( !$wgMemc->add( $key, 1, 3600 ) ) {
+ $wgMemc->incr( $key, 1 );
+ }
+ }
+}
+
+/**
+ * @param File $img
+ * @param string $thumbName
+ * @return string
+ */
+function wfThumbAttemptKey( File $img, $thumbName ) {
+ global $wgAttemptFailureEpoch;
+
+ return wfMemcKey( 'attempt-failures', $wgAttemptFailureEpoch,
+ $img->getRepo()->getName(), md5( $img->getName() ), md5( $thumbName ) );
+}
+