Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / memcache / src / DrupalMemcacheBase.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\memcache\DrupalMemcacheBase.
6  */
7
8 namespace Drupal\memcache;
9
10 use Psr\Log\LogLevel;
11
12 /**
13  * Class DrupalMemcacheBase.
14  */
15 abstract class DrupalMemcacheBase implements DrupalMemcacheInterface {
16
17   /**
18    * The memcache config object.
19    *
20    * @var \Drupal\memcache\DrupalMemcacheConfig
21    */
22   protected $settings;
23
24   /**
25    * The memcache object.
26    *
27    * @var mixed
28    *   E.g. \Memcache|\Memcached
29    */
30   protected $memcache;
31
32   /**
33    * The hash algorithm to pass to hash(). Defaults to 'sha1'
34    *
35    * @var string
36    */
37   protected $hashAlgorithm;
38
39   /**
40    * The prefix memcache key for all keys.
41    *
42    * @var string
43    */
44   protected $prefix;
45
46   /**
47    * Constructs a DrupalMemcacheBase object.
48    *
49    * @param \Drupal\memcache\DrupalMemcacheConfig
50    *   The memcache config object.
51    */
52   public function __construct(DrupalMemcacheConfig $settings) {
53     $this->settings = $settings;
54
55     $this->hashAlgorithm = $this->settings->get('key_hash_algorithm', 'sha1');
56     $this->prefix = $this->settings->get('key_prefix', '');
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function get($key) {
63     $full_key = $this->key($key);
64     return $this->memcache->get($full_key);
65   }
66
67   /**
68    * {@inheritdoc}
69    */
70   public function key($key) {
71     $full_key = urlencode($this->prefix . '-' . $key);
72
73     // Memcache only supports key lengths up to 250 bytes.  If we have generated
74     // a longer key, we shrink it to an acceptable length with a configurable
75     // hashing algorithm. Sha1 was selected as the default as it performs
76     // quickly with minimal collisions.
77     if (strlen($full_key) > 250) {
78       $full_key = urlencode(hash($this->hashAlgorithm, $this->prefix . '-' . $key));
79     }
80
81     return $full_key;
82   }
83
84   /**
85    * {@inheritdoc}
86    */
87   public function delete($key) {
88     $full_key = $this->key($key);
89     return $this->memcache->delete($full_key, 0);
90   }
91
92   /**
93    * {@inheritdoc}
94    */
95   public function flush() {
96     $this->memcache->flush();
97   }
98
99 }