PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 3.11.0
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v3.11.0
4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 3.12.1 All 134 releases
optimole-wp / inc / attachment_cache.php

attachment_cache.php in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 3.11.0, at inc/attachment_cache.php

49 lines 1016 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Optml_Attachment_Cache.
5 */
6 class Optml_Attachment_Cache {
7 const CACHE_GROUP = 'optml_attachment_ids';
8
9 /**
10 * Get the cached attachment ID.
11 *
12 * @param string $url the URL of the attachment.
13 *
14 * @return bool|mixed
15 */
16 public static function get_cached_attachment_id( $url ) {
17 $cache_key = self::get_cache_key( $url );
18
19 return wp_cache_get( $cache_key, self::CACHE_GROUP );
20 }
21
22 /**
23 * Set the cached attachment ID.
24 *
25 * @param string $url the URL of the attachment.
26 * @param int $id the attachment ID.
27 *
28 * @return void
29 */
30 public static function set_cached_attachment_id( $url, $id ) {
31 $cache_key = self::get_cache_key( $url );
32
33 wp_cache_set( $cache_key, $id, self::CACHE_GROUP, DAY_IN_SECONDS );
34 }
35
36 /**
37 * Generate cache key for URL.
38 *
39 * @param string $url the URL to generate the cache key for.
40 *
41 * @return string
42 */
43 private static function get_cache_key( $url ) {
44 $url = strtok( $url, '?' );
45
46 return 'attachment_id_' . crc32( $url );
47 }
48 }
49